ADF.control = ADF.control || {};
ADF.domControl = ADF.domControl || {};
ADF.model = ADF.model || {};
ADF.policy = ADF.policy || {};
ADF.editpart = ADF.editpart || {};
ADF.figure = ADF.figure || {};
ADF.action = ADF.action || {};
ADF.actionModel = ADF.actionModel || {};


ADF.tool = ADF.tool || {};
ADF.property = ADF.property || {};
ADF.propertyDescriptor = ADF.propertyDescriptor || {};


ADF.EditPolicy = ADF.EditPolicy || {};ADF.EditPolicy.LAYOUT_ROLE = "ADFLayoutRolePolicy";ADF.util.Pair = function(key , value) {
    ADF.util.Pair.superclass.constructor.call(this);
    this.key = key ;
	this.value = value;
}

var ThisClass = ADF.util.Pair;

COM.util.defineClass(ThisClass, Object, {
	getKey : function(){
		return this.key;
	},
	
	setKey : function(key){
		this.key = key;
	},
	
	getValue : function(){
		return this.value;
	},
	
	setValue : function(value){
		this.value = value;
	}
});

///////////////////////////////////////////////////////////////////////////
ADF.util.DashedPolyline = function(dashlen , gaplen , id) {
	ADF.util.DashedPolyline.superclass.constructor.call(this, id);
	this.dashlen = dashlen;
	this.gaplen = gaplen;
};

var ThisClass = ADF.util.DashedPolyline;

COM.util.defineClass(ThisClass, COM.draw2d.Polyline, {
	outlineShape : function(graphics){
		graphics.dashedPolyline(this.points,this.dashlen,this.gaplen);
	}
});

////////////////////////////////////////////////////////////////////////////
ADF.util.LabelFeedback = function(layer , text , ico) {
    ADF.util.LabelFeedback.superclass.constructor.call(this);
    this.feedbackLayer = layer;
	this.text = text;
	this.panel = new COM.draw2d.Figure();
	this.panel.setBorder(new COM.draw2d.CompoundBorder(new COM.draw2d.LineBorder(), new COM.draw2d.MarginBorder(0, 2, 0, 2)));
	//��������
	this.panel.setFont();
	// this.panel.setBackgroundColor(COM.draw2d.ColorConstants.red);
	//���ò���
	this.panel.setLayoutManager(new COM.draw2d.XYLayout());
	this.label = new COM.draw2d.Label();
	this.label.setOpaque(true);
	this.label.setForegroundColor(COM.draw2d.ColorConstants.black);
	this.label.setText(text);
	// this.label.setBackgroundColor(COM.draw2d.ColorConstants.yellow);
	if(ico){
		this.label.setIcon(ico);
	}
	this.panel.add(this.label , new COM.draw2d.Rectangle(0,0,-1,-1));
	this.updatePanelSize(); 

	this.feedbackLayer.add(this.panel);
}

var ThisClass = ADF.util.LabelFeedback;

COM.util.defineClass(ThisClass, Object, {
	// getFor : function(host){
	// 	return new UIXYLayoutEditPolicy();
	// },
	
	updatePanelSize : function(){
		this.panel.validate();
		this.size = this.panel.getPreferredSize();
		this.panel.setSize(this.size);

		// this.label.setBorder(new COM.draw2d.LineBorder());
		// this.label.setSize(new COM.draw2d.Dimension(100, 28));
		// this.panel.setSize(new COM.draw2d.Dimension(100, 30));
	},
	
	setText : function(text){
		this.label.setText(text);
		this.updatePanelSize();
	},
	
	setBackgroundColor : function(color){
		this.panel.setBackgroundColor(color);
	},
	
	setIcon : function(icon){
		this.label.setIcon(icon);
		this.updatePanelSize();
	},
	
	getFigure : function(){
		return this.panel;
	},

	getLabel : function(){
		return this.label;
	}
	
});//--------------Class SnapToElement------------------------------
ADF.util.SnapToElement = function() {
    ADF.util.SnapToElement.superclass.constructor.call(this);
}

var ThisClass = ADF.util.SnapToElement;

COM.util.defineClass(ThisClass, Object,{
	makeAbsolute : function(figure , t){
		figure.translateToAbsolute(t);
	},
	
	makeRelative : function(figure , t){
		figure.translateToRelative(t);
	},
	
	snapPoint : function(request , snapLocations , rects , result){
			var resultRect = new COM.draw2d.Rectangle();
			snapLocations = this.snapRectangleAll(request, snapLocations, rects, resultRect);
			result.x = result.x + resultRect.x;
			result.y = result.y + resultRect.y;
			return snapLocations;
	},
	
	snapRectangleAll : function(request , snapOrientation , baseRects , result){
		for (var i = 0; i < baseRects.length && snapOrientation != 0; i++)
			snapOrientation = this.snapRectangle(request, snapOrientation,
					baseRects[i], result);

		return snapOrientation;
	},
				
	getSnapBrother : function(baseRect , direction , target, request){
		var rect = baseRect.getCopy();
		this.result_h = null;
		this.result_v = null;
		this.min_h =  99999;
		this.min_v =  99999;
		var snapDistance = this.getSnapDistance();
		//�����������е�����ͼ��
		//host.getViewer._editParts
//		var editParts = this.host.getViewer()._editParts;
		var rootPart = this.host.getViewer().getRootEditPart();
		var editParts = new Array();
		editParts = this.getAllChildren(rootPart , editParts , target);
		var h_hasline = false;
		var v_hasline = false;
		var moveDelta = request.moveDelta;
		var resizeDelta = request.resizeDelta;
		for(var i =0 ; i < editParts.length ; i++){
			var figure = editParts[i].getFigure();
			var bounds = figure.getBounds().getCopy();
			this.makeAbsolute(figure, bounds);
			var distance;
			if ((direction &COM.draw2d.PositionConstants.EAST) != 0 || (direction &COM.draw2d.PositionConstants.WEST) != 0) {
				if (this.isMove || (!this.isMove && (direction &COM.draw2d.PositionConstants.WEST) != 0)) {
					var value= bounds.x -rect.x ;
					distance =this.getAbs(value);//ȡ����ֵ
					if (distance <= snapDistance && distance < this.min_h && !v_hasline) {
						min_h = distance;
						//Pare ����Map�洢��ֵ�Զ���
						this.result_h = new ADF.util.Pair(figure,COM.draw2d.PositionConstants.WEST);
						this.pt1 = rect.getTopLeft();
						this.pt2 = rect.getBottomLeft();
						w = rect.getTopLeft().x;
						if(moveDelta.x != 0){
							v_hasline = true;
						}
					}
					distance = this.getAbs(bounds.x + bounds.width - rect.x);
					
					if (distance <= snapDistance && distance < this.min_h && !v_hasline) {
						min_h = distance;
						this.result_h = new ADF.util.Pair(figure,COM.draw2d.PositionConstants.EAST);
						this.pt1 = rect.getTopLeft();
						this.pt2 = rect.getBottomLeft();
						if(moveDelta.x != 0){
							v_hasline = true;
						}
					}
				}
				if (this.isMove || (!this.isMove && (direction &COM.draw2d.PositionConstants.EAST) != 0)) {
					distance = this.getAbs(bounds.x - rect.x - rect.width);
					if (distance <= snapDistance && distance < this.min_h && !v_hasline) {
						min_h = distance;
						this.result_h = new ADF.util.Pair(figure,COM.draw2d.PositionConstants.WEST);
						this.pt1 = rect.getTopRight();
						this.pt2 = rect.getBottomRight();
						if(moveDelta.x == 0 && resizeDelta.width != 0){
							v_hasline = true;
						}
					}
					distance = this.getAbs(bounds.x + bounds.width - rect.x - rect.width);
					if (distance <= snapDistance && distance < this.min_h && !v_hasline) {
						min_h = distance;
						this.result_h = new ADF.util.Pair(figure,COM.draw2d.PositionConstants.EAST);
						this.pt1 = rect.getTopRight();
						this.pt2 = rect.getBottomRight();
						if(moveDelta.x == 0 && resizeDelta.width != 0){
							v_hasline = true;
						}
					}
				}
			}
			if ((direction & COM.draw2d.PositionConstants.NORTH) != 0 || (direction & COM.draw2d.PositionConstants.SOUTH) != 0) {
				if (this.isMove || (!this.isMove && (direction & COM.draw2d.PositionConstants.NORTH) != 0)) {
					distance = this.getAbs(bounds.y - rect.y);
					if (distance <= snapDistance && distance < this.min_v  && !h_hasline) {
						min_v = distance;
						this.result_v = new ADF.util.Pair(figure, COM.draw2d.PositionConstants.NORTH);
						this.pt3 = rect.getTopLeft();
						this.pt4 = rect.getTopRight();
						if(moveDelta.y != 0){
							h_hasline = true;
						}
					}
					distance = this.getAbs(bounds.y + bounds.height - rect.y);
					if (distance <= snapDistance && distance < this.min_v && !h_hasline) {
						min_v = distance;
						this.result_v = new ADF.util.Pair(figure, COM.draw2d.PositionConstants.SOUTH);
						this.pt3 = rect.getTopLeft();
						this.pt4 = rect.getTopRight();
						if(moveDelta.y != 0){
							h_hasline = true;
						}
					}
				}
				if (this.isMove || (!this.isMove && (direction & COM.draw2d.PositionConstants.SOUTH) != 0)) {
					distance = this.getAbs(bounds.y - rect.y - rect.height);
					if (distance <= snapDistance && distance < this.min_v && !h_hasline) {
						min_v = distance;
						this.result_v = new ADF.util.Pair(figure, COM.draw2d.PositionConstants.NORTH);
						this.pt3 = rect.getBottomLeft();
						this.pt4 = rect.getBottomRight();
						if(moveDelta.y == 0 && resizeDelta.height != 0){
							h_hasline = true;
						}
					}
					distance = this.getAbs(bounds.y + bounds.height - rect.y - rect.height);
					if (distance <= snapDistance && distance < this.min_v && !h_hasline) {
						min_v = distance;
						this.result_v = new ADF.util.Pair(figure, COM.draw2d.PositionConstants.SOUTH);
						this.pt3 = rect.getBottomLeft();
						this.pt4 = rect.getBottomRight();
						if(moveDelta.y == 0 && resizeDelta.height != 0){
							h_hasline = true;
						}
					}
				}
			}
		}
	},
	/**
	 * ��ȡ���е���EditPart
	 */
	getAllChildren : function(root , editparts , target){
		var children = root.getChildren();
		 for (var i =0 ; i < children.length ; i++){
			 if(children[i].getChildren().length != 0){
				 this.getAllChildren(children[i] , editparts);
			 }
			 if(!target){
				 target = this.host.getViewer().getSelection()[0];
			 }
			 
			//  if(!children[i].isEditable() 
			//  //	@TODO king
			// 		//  || children[i] instanceof UIEditor.DesignPanelContentEditPart 
			// 		 || children[i]._id == target._id
			// 		 || children[i].getParent().getFigure().getBounds().x == 10000)
			// 	 continue;
			 editparts.push(children[i]);
		 }
		 
		 return editparts;
	},
	
	
	/**
	 * ����ȫ�ֱ�����
	 */
	getSnapDistance : function(){
		return 5;
	},
	
	setHostPart : function(host){
		this.host = host;
	},
	
	getAbs : function(value){
		return (value < 0) ? -value : value;
	},
	
	snapRectangle : function(request, snapOrientation,
			baseRect , result , target){
		var direction = this.getDirection(request);
		this.pt1 = null;
		this.pt2 = null;
		this.pt3 = null;
		this.pt4 = null;
		this.getSnapBrother(baseRect, direction , target,request);
		this.eraseLineFeedback();
		this.handleHorizontal(baseRect, result, direction);
		this.handleVertical(baseRect, result, direction);
		return snapOrientation;
	},
	
	getDirection : function(request){
		var direction = 0;
		if (COM.gef.RequestConstants.REQ_ADD == request.getType()
				|| COM.gef.RequestConstants.REQ_CLONE == request.getType()
				|| COM.gef.RequestConstants.REQ_MOVE == request.getType()
				|| COM.gef.RequestConstants.REQ_MOVE_CHILDREN == request.getType()) {
			this.isMove = true;
			this.isCreate = false;
			direction = COM.draw2d.PositionConstants.NSEW;
		}
		if (COM.gef.RequestConstants.REQ_RESIZE == request.getType()
				|| COM.gef.RequestConstants.REQ_RESIZE_CHILDREN == request.getType()) {
			this.isMove = false;
			this.isCreate = false;
			direction = COM.draw2d.PositionConstants.NSEW;
		}
		if (COM.gef.RequestConstants.REQ_CREATE == request.getType()) {
			this.isMove = false;
			this.isCreate = true;
			var moveDelta = this.getDragMoveDelta();
			if (moveDelta != null) {
				if (moveDelta.width > 0) {
					direction |= COM.draw2d.PositionConstants.EAST;
				} else if (moveDelta.width < 0) {
					direction |= COM.draw2d.PositionConstants.WEST;
				}
				if (moveDelta.height > 0) {
					direction |= COM.draw2d.PositionConstants.SOUTH;
				} else if (moveDelta.height < 0) {
					direction |= COM.draw2d.PositionConstants.NORTH;
				}
			}
		}
		if (COM.gef.RequestConstants.REQ_PASTE == request.getType()) {
			
		}
		return direction;
 },
	
	handleHorizontal : function(baseRect, result, direction){
		if (this.pt1 == null || this.pt2 == null) {
			return;
		}
		var startPoint = null;
		var endPoint = null;
		if (this.result_h != null && this.result_h.getKey() != null) {
			var figure = this.result_h.getKey();
			var b = figure.getBounds().getCopy();
			this.makeAbsolute(figure, b);
			var p1 = null;
			var p2 = null;
			var border = this.result_h.getValue();
			switch (border) {
			case COM.draw2d.PositionConstants.EAST:
				p1 = b.getTopRight();
				p2 = b.getBottomRight();
				break;
			case COM.draw2d.PositionConstants.WEST:
				p1 = b.getTopLeft();
				p2 = b.getBottomLeft();
				break;
				
			default :
				break;
			}
			if (p1 == null || p2 == null) {
				return;
			}
			if ((direction &COM.draw2d.PositionConstants.WEST) != 0) {
				if (this.isCreate) {
					result.x = result.x + p1.x - this.pt1.x;
				} else {
					result.x = p1.x - this.pt1.x;
				}
				if (!this.isMove) {
					result.width = result.width + this.pt1.x - p1.x;
				}
				startPoint = new COM.draw2d.Point(p1.x, this.getMin(this.pt1.y, this.pt2.y, p1.y, p2.y));
				endPoint = new COM.draw2d.Point(p1.x, this.getMax(this.pt1.y,this. pt2.y, p1.y, p2.y));
			}
			if ((direction &COM.draw2d.PositionConstants.EAST) != 0) {
				if (this.isMove) {
					if (this.isCreate) {
						result.x = result.x + p1.x - this.pt1.x;
					} else {
						result.x = p1.x - this.pt1.x;
					}
				} else {
					result.width = result.width + p1.x - this.pt1.x;
				}
				startPoint = new COM.draw2d.Point(p1.x, this.getMin(this.pt1.y, this.pt2.y, p1.y, p2.y));
				endPoint = new COM.draw2d.Point(p1.x, this.getMax(this.pt1.y, this.pt2.y, p1.y, p2.y));
			}
		}
		if (startPoint != null && endPoint != null) {
			this.addLineFeedback(startPoint, endPoint , this.host);
		}
	},
	
	handleVertical : function(baseRect, result, direction){
		if (this.pt3 == null || this.pt4 == null) {
			return;
		}
		var startPoint = null;
		var endPoint = null;
		if (this.result_v != null && this.result_v.getKey() != null) {
			var figure = this.result_v.getKey();
			var b = figure.getBounds().getCopy();
			this.makeAbsolute(figure, b);
			var p1 = null;
			var p2 = null;
			var border = this.result_v.getValue();
			switch (border) {
			case COM.draw2d.PositionConstants.NORTH:
				p1 = b.getTopLeft();
				p2 = b.getTopRight();
				break;
			case COM.draw2d.PositionConstants.SOUTH:
				p1 = b.getBottomLeft();
				p2 = b.getBottomRight();
				break;
			default :
				break ;
		
			}
			if (p1 == null || p2 == null) {
				return;
			}
			if ((direction & COM.draw2d.PositionConstants.NORTH) != 0) {
				if (this.isCreate) {
					result.y = result.y + p1.y - this.pt3.y;
				} else {
					result.y = p1.y - this.pt3.y;
				}
				if (!this.isMove) {
					result.height = result.height + this.pt3.y - p1.y;
				}
				startPoint = new COM.draw2d.Point(this.getMin(this.pt3.x, this.pt4.x, p1.x, p2.x), p1.y);
				endPoint = new COM.draw2d.Point(this.getMax(this.pt3.x, this.pt4.x, p1.x, p2.x), p1.y);
			}
			if ((direction & COM.draw2d.PositionConstants.SOUTH) != 0) {
				if (this.isMove) {
					if (this.isCreate) {
						result.y = result.y + p1.y - this.pt3.y;
					} else {
						result.y = p1.y - this.pt3.y;
					}
				} else {
					result.height = result.height + p1.y - this.pt3.y;
				}
				startPoint = new COM.draw2d.Point(this.getMin(this.pt3.x, this.pt4.x, p1.x, p2.x), p1.y);
				endPoint = new COM.draw2d.Point(this.getMax(this.pt3.x, this.pt4.x, p1.x, p2.x), p1.y);
			}
		}
		if (startPoint != null && endPoint != null) {
			this.addLineFeedback(startPoint, endPoint , this.host);
		}
	},
	
	getMax : function(v1 ,v2 , v3 , v4){
			var result = v1;
			if(v2 > result)
				result = v2;
			if(v3 > result)
				result = v3;
			if(v4 > result)
				result = v4;
			return result ;
	},
	
	getMin : function(v1 ,v2 , v3 , v4){
		var result = v1;
		if(v2 < result)
			result = v2;
		if(v3 < result)
			result = v3;
		if(v4 < result)
			result = v4;
		return result ;
	},
	
	addLineFeedback : function(startPoint, endPoint ,host){
		this.editpolicy.addLineFeedback(startPoint, endPoint , host);
	},
	
	eraseLineFeedback : function(){
		this.editpolicy.eraseLineFeedback(this.host);
	},
	
	getEditpolicy : function(){
		return this.editpolicy;
	},
	
	setEditpolicy : function(editpolicy){
		this.editpolicy = editpolicy;
	},
	
	getDragMoveDelta : function(){
		this.host.getViewer().getBench().getActiveTool().getDragMoveDelta();
	}
	
});

/**
 * @author jiangqifan
 * @since 2016-5-26
 */

(function(){
  ADF.policy.SnapPolicy = function(){
    ThisClass.superclass.constructor.call(this);
	
	this.policiesHasLineFeedback = new Array();
	this.lineFeedbacks = new Array();
  }

  var ThisClass = ADF.policy.SnapPolicy;

  //static properties
  COM.util.defineClass(ThisClass, COM.gef.ConstrainedLayoutEditPolicy, {
    
    getConstraintFor: function(request, child) {
      var rectangle = new COM.draw2d.Rectangle(), childBoundsCopy = child.getModel().getBounds().copy(),
          childFigure = child.getFigure(), moveData = request.getMoveDelta();
      childFigure.translateToAbsolute(childBoundsCopy);
      var relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x + moveData.x , childBoundsCopy.y + moveData.y);
      rectangle.setLocation(relativeLoaction);
      rectangle.setSize(child.getFigure().getBounds().getSize());
      return rectangle;
    },

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	
	// 	getFor : function(host){
// 		var layout = null;
// 		if(host!=null&&host!="undefined"){
			
// 		}
// 		return new UIEditor.UIXYLayoutEditPolicy();
// 	},
	
	getCommand : function(request){
		return null;
// //		if (REQ_PASTE.equals(request.getType()))
// //			return getPasteCommand((PasteRequest) request);
// //		if (REQ_MOVE_CHILDREN.equals(request.getType()))
// //			return getResizeChildrenCommand((ChangeBoundsRequest)request);
// 		if(COM.gef.RequestConstants.REQ_DELETE == request.getType())
// 			return this.getDeleteChildrenIncident(request,host);
// 		if(COM.gef.RequestConstants.REQ_MOVE == request.getType() || COM.gef.RequestConstants.REQ_RESIZE == request.getType()){
// 			if(request.getCause)
// 				if(request.getCause() == "vernier_changebounds")
// 					return this.getVernierChangeConstraintCommand(request,host);
// 		}
// 		return UIEditor.UIXYLayoutEditPolicy.superclass.getIncident.call(this,request,host);
	},
	
// 	getVernierChangeConstraintCommand : function(request,host){
// 		var child = request.getEditParts()[0];
// 		var direction = request.getDirection();
// 		var moveDelta = request.getMoveDelta();
// 		var sizeDelta = request.getSizeDelta();
		
// 		var oldBound = child.getFigure().getBounds().getCopy();
// 		var newBound = oldBound.getCopy();
// 		newBound.x = oldBound.x + moveDelta.x;
// 		newBound.y = oldBound.y + moveDelta.y;
// 		newBound.width = oldBound.width + sizeDelta.width;
// 		newBound.height = oldBound.height + sizeDelta.height;
		
// 		if(newBound.x<0) { newBound.x = 0; }
// 		if(newBound.y<0) { newBound.y = 0; }
		
// 		var inc = new UIEditor.DesignPanelIncident(host.getId() , UIEditor.DesignPanelIncident.XY_TYPE_GRAPHIC_MOVE );
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_POSITION_X, oldBound!=null?oldBound.x:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_POSITION_Y, oldBound!=null?oldBound.y:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_SIZE_WIDTH, oldBound!=null?oldBound.width:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_SIZE_HEIGHT, oldBound!=null?oldBound.height:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_X, newBound!=null?newBound.x:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_Y, newBound!=null?newBound.y:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_WIDTH, newBound!=null?newBound.width:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_HEIGHT, newBound!=null?newBound.height:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_CHILD_ID, child.getId());
// 		return inc;
// 	},
	
// 	getDeleteChildrenIncident : function(request,host){
// 		var child = request.getEditParts()[0];
// 		var inc = new UIEditor.DesignPanelIncident(host.getId() , UIEditor.DesignPanelIncident.XY_TYPE_GRAPHIC_CHILD_DELETE );
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_CHILD_ID, child.getId());
// 		return inc;
// 	},
	
// 	getTargetEditPart : function(request,host){
// 		//��Ҫ���¶���
// //		if (REQ_PASTE.equals(request.getType()))
// //			return host;
// 		return UIEditor.UIXYLayoutEditPolicy.superclass.getTargetEditPart.call(this,request,host);
// 	},
	
// 	// override
// 	createChangeConstraintIncidentWithRequest : function(request,child,constraint,host){
// 		var oldBound = child.getFigure().getBounds().getCopy();
// 		constraint.x = (constraint.x < 0 ? 0 : constraint.x);
// 		constraint.y = (constraint.y < 0 ? 0 : constraint.y);
		
		
// 		var inc = new UIEditor.DesignPanelIncident(host.getId() , UIEditor.DesignPanelIncident.XY_TYPE_GRAPHIC_MOVE );
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_POSITION_X, oldBound!=null?oldBound.x:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_POSITION_Y, oldBound!=null?oldBound.y:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_SIZE_WIDTH, oldBound!=null?oldBound.width:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.OLD_DATA_SIZE_HEIGHT, oldBound!=null?oldBound.height:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_X, constraint!=null?constraint.x:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_Y, constraint!=null?constraint.y:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_WIDTH, constraint!=null?constraint.width:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_HEIGHT, constraint!=null?constraint.height:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_CHILD_ID, child.getId());
// 		return inc;
// 	},
// 	createChangeConstraintIncident : function(child,constraint,host){
// 		return null;
// 	},
	
// 	getCreateIncident : function(request,host){
// 		var inc = new UIEditor.DesignPanelIncident(host.getId() , UIEditor.DesignPanelIncident.XY_TYPE_GRAPHIC_CREATE);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_CREATE_ACTIVETOOL , request.getCreationType());
// 		var COM.draw2d.Point = request.getLocation().getCopy();
// 		host.getFigure().translateToRelative(COM.draw2d.Point);
// 		host.getFigure().translateFromParent(COM.draw2d.Point);
// //		this.translate(host.getFigure()._eid, COM.draw2d.Point);
// 		if(COM.draw2d.Point.x < 0 || COM.draw2d.Point.y < 0) {
// 			this.eraseCreateFlagFeedback(host);
// 			return null;
// 		}
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_X , COM.draw2d.Point.x);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_Y , COM.draw2d.Point.y);
// 		var cell = UIEditor.designerPanelToolKit.getCellPoint(host.getFigure()._eid , COM.draw2d.Point.x , COM.draw2d.Point.y);
// 		if(cell){
// 			inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_COLUMN , cell.x);
// 			inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_ROW , cell.y);
// 		}
// 		if(request.getSize()!=null){
// 			var size = request.getSize().getCopy();
// 			host.getFigure().translateToRelative(size);
// 			host.getFigure().translateFromParent(point);
// 			inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_WIDTH , size.width);
// 			inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_SIZE_HEIGHT , size.height);
// 		}
// 		return inc;
// 	},
// 	/**
// 	 * ճ��������ע�ֽ׶��Ȳ�֧��
// 	 */
// 	getPasteIncident : function(request,host){
// 		return null;
// 	},
	
// 	createAddIncident : function(child,constraint , host){
// 		var inc = new UIEditor.DesignPanelIncident(host.getId() , UIEditor.DesignPanelIncident.XY_TYPE_GRAPHIC_CHILD_ADD)
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_X, constraint!=null?constraint.x:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_POSITION_Y, constraint!=null?constraint.y:undefined);
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_CHILD_ID, child.getId());
// 		inc.setArgumentByKey(UIEditor.DesignPanelIncident.DATA_PARENT_ID, child.getParent().getId());
// 		return inc;
// 	},
	
// 	getCloneIncident : function(request,host){
// 		//�ֽ׶β�֧��
// 		return null;
// 	},
	
	eraseLayoutTargetFeedback : function(request){
		this.eraseLocationFeedback();
		this.eraseSizeFeedback();
		this.eraseLineFeedback();
	},
	
	eraseLocationFeedback : function(){
		if (this.locationFeedback != undefined && this.locationFeedback != null) {
			this.removeFeedback(this.locationFeedback.getFigure());
			this.locationFeedback = null;
		}
	},
	
	eraseSizeFeedback : function(){
		if (this.sizeFeedback != undefined && this.sizeFeedback != null) {
			this.removeFeedback(this.sizeFeedback.getFigure());
			this.sizeFeedback = null;
		}
	},
	
	eraseCreateFlagFeedback : function(){
		if (this.createFlagFeedback != undefined && this.createFlagFeedback != null) {
			this.removeFeedback(this.createFlagFeedback.getFigure());
			this.createFlagFeedback = null;
		}
	},
	
	eraseLineFeedback : function(){
		if (!this.lineFeedbacks.length == 0) {
			for (var i = 0 ; i < this.lineFeedbacks.length; i++) {
				this.removeSubFeedback(this.lineFeedbacks[i]);
			}
			this.lineFeedbacks.length = 0;
			COM.util.Array.removeItem(this.policiesHasLineFeedback , this);
		}
	},
	
	/**
	 * @overwride
	 */
	eraseTargetFeedback : function(request){
		if (COM.gef.RequestConstants.REQ_ADD == (request.getType())
				|| COM.gef.RequestConstants.REQ_CLONE == (request.getType())
				|| COM.gef.RequestConstants.REQ_MOVE == (request.getType())
				|| COM.gef.RequestConstants.REQ_MOVE_CHILDREN == (request.getType())
				|| COM.gef.RequestConstants.REQ_RESIZE == (request.getType())
				|| COM.gef.RequestConstants.REQ_RESIZE_CHILDREN == (request.getType())
				|| COM.gef.RequestConstants.REQ_CREATE == (request.getType())
				|| COM.gef.RequestConstants.REQ_PASTE == (request.getType()))
			this.eraseLayoutTargetFeedback(request);

		if (COM.gef.RequestConstants.REQ_CREATE == (request.getType())){
			this.eraseSizeOnDropFeedback(request);
		    this.eraseCreateFlagFeedback();
		}
	},
	
	/**
	 * overwride
	 */
	eraseSizeOnDropFeedback : function(request){
		this.eraseSizeFeedback();
		this.isa = "SnapPolicy";
		return ADF.policy.SnapPolicy.superclass.eraseSizeOnDropFeedback.call(this,request);
	},
	
	showTargetFeedback : function(request){
		//�����������������һ�ȥ����request
		if(COM.gef.RequestConstants.REQ_RESIZE == (request.getType())
				|| COM.gef.RequestConstants.REQ_ADD == (request.getType())
				|| COM.gef.RequestConstants.REQ_MOVE == (request.getType())){
			this.showLineFeedback(request);
		}
		
		if (COM.gef.RequestConstants.REQ_ADD == (request.getType())
				|| COM.gef.RequestConstants.REQ_CLONE == (request.getType())
				|| COM.gef.RequestConstants.REQ_MOVE == (request.getType())
				|| COM.gef.RequestConstants.REQ_MOVE_CHILDREN == (request.getType())
				|| COM.gef.RequestConstants.REQ_RESIZE == (request.getType())
				|| COM.gef.RequestConstants.REQ_RESIZE_CHILDREN == (request.getType())
				|| COM.gef.RequestConstants.REQ_CREATE == (request.getType())
				|| COM.gef.RequestConstants.REQ_PASTE == (request.getType()))
			this.showLayoutTargetFeedback(request);

		if (COM.gef.RequestConstants.REQ_CREATE == (request.getType())) {
			this.showCreateFeedback(request);
		}
		
		
	},
	
	showLineFeedback : function(request){
		host = this.getHost();
		var editparts = request.getEditParts();
		var compoundSrcRect = null;
		var sourceRectangle = null;
		for(var i =0 ; i < editparts.length ; i++){
			var editpart = editparts[i];
			var figure = editpart.getFigure();
			var sourceRect = figure.getBounds().getCopy();
			if(COM.gef.RequestConstants.REQ_RESIZE== (request.getType())){
				var  rect = sourceRect.getCopy();
				figure.translateToAbsolute(rect);
				rect.translate(request.getMoveDelta());
				rect.resize(request.getSizeDelta());
				var result = new COM.draw2d.Point();
				this.getSnapToHelper(host).snapRectangle(request , request.getResizeDirection(),
						rect, result , editpart);
				
				if (request.isCenteredResize()) {
					if (result.x != 0)
						result.width(result.width - result.x);
					else if (result.width() != 0) {
						result.x = -result.width();
						result.width = result.width * 2;
					}

					if (result.y != 0)
						result.height = result.height - result.y;
					else if (result.height() != 0) {
						result.y = -result.height;
						result.height = result.height * 2;
					}
				}
				var movex = request.getMoveDelta().x;
				var movey = request.getMoveDelta().y;
				var resizeW = result.x + request.getSizeDelta().width;
				var resizeH = result.y + request.getSizeDelta().height;
				
				if(movex != 0){
					movex += result.x;
					resizeW -= 2 * result.x
				}
				if(movey != 0){
					movey += result.y;
					resizeH -= 2 * result.y
				}
				var move = new COM.draw2d.Point(movex, movey);
				var resize = new COM.draw2d.Dimension(resizeW, resizeH);

				request.setMoveDelta(move);
				request.setSizeDelta(resize);
				editpart.showSourceFeedback(request);
			}
			
			if(COM.gef.RequestConstants.REQ_MOVE == (request.getType()) || COM.gef.RequestConstants.REQ_ADD == (request.getType())){
				figure.translateToAbsolute(sourceRect);
				if(compoundSrcRect == null)
					var compoundSrcRect = sourceRect.getCopy();
				else
					compoundSrcRect = compoundSrcRect.union(sourceRect);
				if(editpart == host.getViewer().getFocusEditPart())
					sourceRectangle = sourceRect;
				}
		}
		
		if(COM.gef.RequestConstants.REQ_MOVE == (request.getType()) || COM.gef.RequestConstants.REQ_ADD == (request.getType())){
			if(sourceRectangle == null){
				var figure = host.getViewer().getSelection()[0].getFigure();
				sourceRectangle = figure.getBounds().getCopy();
				figure.translateToAbsolute(sourceRectangle);
			}
			var result = request.getMoveDelta().getCopy();
			var rects = new Array();
			sourceRectangle.translate(request.getMoveDelta());
			rects.push(sourceRectangle);
			if(compoundSrcRect) {
				compoundSrcRect.translate(request.getMoveDelta());
				rects.push(compoundSrcRect);
			}
			this.getSnapToHelper(host).snapPoint(request, COM.draw2d.PositionConstants.HORIZONTAL | COM.draw2d.PositionConstants.VERTICAL, rects , result);
			request.setMoveDelta(result);
		}
		
	},
	
	getSnapToHelper : function(host){
		if(this.snapToHelper == null){
			this.snapToHelper = new ADF.util.SnapToElement();
			this.snapToHelper.setEditpolicy(this);
		}
		this.snapToHelper.setHostPart(this.getHost());
		return this.snapToHelper;
	},
	
	addLineFeedback : function(startPoint , endPoint){
		this.eraseOtherLineFeedback(this);
		var p1 = startPoint.getCopy();
		var p2 = endPoint.getCopy();
		var layer = this.getFeedbackLayer();
		layer.translateToRelative(p1);
		layer.translateToRelative(p2);
		var line = new ADF.util.DashedPolyline(5 , 5);
		this.initFeedbackLine(line);
		line.addPoint(p1);
		line.addPoint(p2);
		var lineFeedback = line;
		this.addSubFeedback(lineFeedback);
		this.lineFeedbacks.push(lineFeedback);
		if (!COM.util.Array.contains(this.policiesHasLineFeedback , this)) {
			this.policiesHasLineFeedback.push(this);
		}
	},
	
	eraseOtherLineFeedback : function(except){
		if (this.policiesHasLineFeedback.length == 0) {
			return;
		}
		for (var i =0; i < this.policiesHasLineFeedback.length; i++) {
			if (this.policiesHasLineFeedback[i] != except) {
				 this.policiesHasLineFeedback[i].eraseLineFeedback();
			}
		}
	},
	
	addSubFeedback : function(feedback){
		this.getFeedbackLayer().add(feedback);
	},
	
	removeSubFeedback : function(feedback){
		this.getFeedbackLayer().remove(feedback);
	},
	
	initFeedbackLine : function(line){
		line.setLineWidth(2);
		line.setOutlineColor(COM.draw2d.ColorConstants.red);
	},
	
	showLayoutTargetFeedback : function(request){
		host = this.getHost();
		var bounds = null;
		if (COM.gef.RequestConstants.REQ_MOVE == request.getType()
				|| COM.gef.RequestConstants.REQ_MOVE_CHILDREN == request.getType()
				|| COM.gef.RequestConstants.REQ_RESIZE == request.getType()
				|| COM.gef.RequestConstants.REQ_ADD == request.getType()
				|| COM.gef.RequestConstants.REQ_RESIZE_CHILDREN == request.getType()) {
			if (request.getEditParts() == null || request.getEditParts().length == 0) {
				return;
			}
			var child = request.getEditParts()[0];
			bounds = this.translateToModelConstraint(this.getConstraintForChangeBounds(
					request, child));
			if (COM.gef.RequestConstants.REQ_MOVE == request.getType()
				|| COM.gef.RequestConstants.REQ_MOVE_CHILDREN == request.getType() || COM.gef.RequestConstants.REQ_ADD == request.getType()) {
				this.doShowLocationFeedback(bounds);
			}
			if (COM.gef.RequestConstants.REQ_RESIZE == request.getType()
				|| COM.gef.RequestConstants.REQ_RESIZE_CHILDREN == request.getType()) {
				this.doShowSizeFeedback(bounds);
			}
		}

		if (COM.gef.RequestConstants.REQ_CREATE == request.getType()
				|| COM.gef.RequestConstants.REQ_PASTE == request.getType()){
			bounds = this.getConstraintForCreate(request);
			this.doShowLocationFeedback(bounds);
			this.doShowSizeFeedback(bounds);
		}
	},
	
	showCreateFeedback : function(request){
		if (request.getSize() == null){
			var d = new COM.draw2d.Dimension(0,0);
			request.setSize(d);
		}
		this.showSizeOnDropFeedback(request);
		
		this.showCreateFlagFeedback(request);
	},
	
	showSizeOnDropFeedback : function(request){
		ADF.policy.SnapPolicy.superclass.showSizeOnDropFeedback.call(this,request);
		var bounds = this.getConstraintForCreate(request);
		this.doShowLocationFeedback(bounds);
		this.doShowSizeFeedback(bounds);
	},
	
	getAbsoluteFromChild : function(bounds) {
		host = this.getHost();
		var traned = bounds.getCopy();
		var figure = host.getFigure();
		figure.translateToParent(traned);
		figure.translateToAbsolute(traned);
		return traned;
	},
	
	doShowLocationFeedback : function(bounds){
		if(bounds.x < 0 || bounds.y < 0) 
			return;

		var feedback = this.getLocationFeedback();
		var label = feedback.getLabel();
		var figure = feedback.getFigure();
		
		var size = figure.getSize();
		var location = this.getAbsoluteFromChild(bounds).getTopLeft().translate(-8 - size.width , -8 - size.height);
		figure.translateToRelative(location);
		figure.setLocation(location);

		var text = bounds.x+","+bounds.y;
		feedback.setText(text);

		figure.repaint();
	},
	getLocationFeedback : function(){
		if (this.locationFeedback == undefined || this.locationFeedback == null) {
			var feedback = new ADF.util.LabelFeedback(this.getFeedbackLayer(), "");
			feedback.setBackgroundColor(COM.draw2d.ColorConstants.yellow);
			this.locationFeedback = feedback;
			this.addFeedback(this.locationFeedback.getFigure());
		}
		return this.locationFeedback;
	},
	
	doShowSizeFeedback : function(bounds){
		if(bounds.width < 0 || bounds.height < 0)
			return ;
		var text = bounds.width+","+bounds.height;
		var location = this.getAbsoluteFromChild(bounds).getBottomRight().translate(12, 8);
		var feedback = this.getSizeFeedback();
		feedback.setText(text);
		feedback.getFigure().setLocation(location);
		feedback.getFigure().repaint();
	},
	
	getSizeFeedback : function(){
		if (this.sizeFeedback ==undefined || this.sizeFeedback == null) {
			var feedback = new ADF.util.LabelFeedback(this.getFeedbackLayer(), "");
			feedback.setBackgroundColor(COM.draw2d.ColorConstants.yellow);
			this.sizeFeedback = feedback;
			this.addFeedback(this.sizeFeedback.getFigure());
		}
		return this.sizeFeedback;
	},
	
	showCreateFlagFeedback : function(request){
		var bounds = this.getConstraintForCreate(request);
		if(bounds.x < 0 || bounds.y < 0 || (bounds.width>0 && bounds.height>0)) {
			this.eraseCreateFlagFeedback();
			return;
		}
		bounds = this.getAbsoluteFromChild(bounds);
		var feedback = this.getCreateFlagFeedback();

		var location = new COM.draw2d.Point(bounds.x + 15, bounds.y + 10);
		feedback.getFigure().translateToRelative(location);
		if (location.x < 0) {
			location.x = 0;
		}
		if (location.y < 0) {
			location.y = 0;
		}
		
		feedback.getFigure().setLocation(location);
		feedback.getFigure().repaint();
	},
	
	
	getCreateFlagFeedback : function(){
		if (this.createFlagFeedback == undefined || this.createFlagFeedback == null) {
			var feedback = new ADF.util.LabelFeedback(this.getFeedbackLayer(), "");
			// feedback.setIcon(UIEditor.UIXYLayoutEditPolicy.OK_IMAGE);
//			feedback.setBackgroundColor(COM.draw2d.ColorConstants.white);
			feedback.panel.setBorder(null);
			this.createFlagFeedback = feedback;
			this.addFeedback(this.createFlagFeedback.getFigure());
		}
		return this.createFlagFeedback;
	},
	
	
// 	eraseCellsFeedback : function(){
// 		if (this.freeCellsFeedbacks != null) {
// 			for (var i =0 ;i<this.freeCellsFeedbacks.length ; i++) {
// 				COM.util.Array.remove(this.freeCellsFeedbacks , i);
// 			}
// 			this.freeCellsFeedbacks = undefined;
// 		}
// 	},

// 	getMinimumSizeFor: function(child){
// 		if (child instanceof UIEditor.NonDiagonalLineEditPart) {
// 			return new COM.draw2d.Dimension(1,1);
// 		} else
// 		return new COM.draw2d.Dimension(8, 8);
// 	},

	/**
	 * overwride
	 */
	 getConstraintForRectangle : function(rectangle){
		 return rectangle;
	 }
  });

})();/**
 * @author zhengjiachao
 * @since 2017-4-6
 */
ADF.domControl.Button = function(parent) {
    ADF.domControl.Button.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Button, ADF.domControl.BaseControl, {
    getLabel: function(){
        return "Button";
    },
    setText: function(text) {
        this.domElement.innerHTML = text;
    },
    setBtnstyle:function(btnstyle){
        $(this.domElement).addClass(btnstyle);
    },

    _getDomElement: function(model) {
        var button = COM.util.HTMLUtil.createELement('<button type="button" class="btn" style="overflow:hidden;">'+model.getText()+'</button>');
        return button[0];
    }

});/**
 * @author zhengjiachao
 * @since 2017-4-6
 */
ADF.policy.ButtonComponentEditPartPolicy = function(){
    ADF.policy.ButtonComponentEditPartPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.ButtonComponentEditPartPolicy, AGEF.ComponentEditPolicy, {
    
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.model.ButtonModel = function(){
    ADF.model.ButtonModel.superclass.constructor.call(this);
};

ADF.model.ButtonModel.PROPERTY_TEXT = "text";
ADF.model.ButtonModel.PROPERTY_BTNSTYLE = "btnstyle";

COM.util.defineClass(ADF.model.ButtonModel, ADF.model.BaseModel,{

    initModel: function() {
        ADF.model.ButtonModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.ButtonModel.PROPERTY_TEXT, "", "", true, "文本"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.ButtonModel.PROPERTY_BTNSTYLE, "btn-default", "", true, "按钮样式"));
    },
    setText: function(text) {
        this.setPropertyValue(ADF.model.ButtonModel.PROPERTY_TEXT, text);
    },
    getText: function() {
        return this.getPropertyValue(ADF.model.ButtonModel.PROPERTY_TEXT);
    },
    setBtnstyle: function(btnstyle) {
        this.setPropertyValue(ADF.model.ButtonModel.PROPERTY_BTNSTYLE, btnstyle);
    },
    getBtnstyle: function() {
        return this.getPropertyValue(ADF.model.ButtonModel.PROPERTY_BTNSTYLE);
    },

    _getModelType : function(){
        return "ADF.model.ButtonModel";
    },

    _getName : function(){
        return 'button';  
    },

    fillSerializedJson : function(jsonObject){
        jsonObject[ADF.model.ButtonModel.PROPERTY_TEXT]=this.getPropertyDescriptor(ADF.model.ButtonModel.PROPERTY_TEXT).serialize();
        jsonObject[ADF.model.ButtonModel.PROPERTY_BTNSTYLE]=this.getPropertyDescriptor(ADF.model.ButtonModel.PROPERTY_BTNSTYLE).serialize();
    },

    _deserialize:function (jsonObject) {
        var newProp=null;

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.ButtonModel.PROPERTY_TEXT]);
        this.propertyDescriptors.put(newProp.getName(),newProp);

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.ButtonModel.PROPERTY_BTNSTYLE]);
        this.propertyDescriptors.put(newProp.getName(),newProp);
    }
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.Button = function() {
    ADF.control.Button.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Button, ADF.ControlDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var buttonFigure = new AGEF.WidgetFigure(this.id);
                var button = this.getWidgetFactory().createControl(this.getModel());
                buttonFigure.setWidget(button);
                return buttonFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new ADF.policy.ButtonComponentEditPartPolicy());
            // },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
                    if (ADF.model.ButtonModel.PROPERTY_TEXT == evt.getPropertyName()) {
                        this.getFigure().getWidget().setText(evt.newValue);
                    } else if (ADF.model.ButtonModel.PROPERTY_BTNSTYLE == evt.getPropertyName()) {
                        this.getFigure().getWidget().setBtnstyle(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.ButtonModel;
    },

    getDomControl : function(){
        return ADF.domControl.Button;
    }

});/**
 * Created by zhangwenlei on 2017/5/9.
 */
ADF.domControl.ButtonGroup = function(parent) {
        ADF.domControl.ButtonGroup.superclass.constructor.call(this, parent);
        this.feedbackDom=null;
    };

    COM.util.defineClass(ADF.domControl.ButtonGroup, ADF.domControl.Composite, {
        getLabel: function(){
            return "ButtonGroup";
        },
        appendDomChild: function(child) {
            this.getDomElement().children[0].appendChild(child);
        },
        removeDomChild: function(child) {
            this.getDomElement().children[0].removeChild(child);
        },
        _getDomElement: function(model) {
            var buttongroup=this.createButtonGroup( );
            var buttongroupWrap=this.createButtongroupWrap(model);
            buttongroupWrap.append(buttongroup);
            this.domElement = buttongroupWrap[0];
            return this.domElement;
        },
        createButtonGroup:function ( ) {
            var buttongroup = COM.util.HTMLUtil.createELement('<div class="btn-group" role="group"></div>');
            var css={"position":"relative","overflow":"visible","width":"100%"};
            css.minHeight=10;
            buttongroup.css(css);
            return buttongroup;
        },
        createButtongroupWrap:function (model) {
            var buttongroupWrap=COM.util.HTMLUtil.createELement('<div class="buttonGroupWrap adf_wrapper"></div>');
            return buttongroupWrap;
        },
        showFeedback:function (height,width) {
          var css={"position":"relative","overflow":"visible","border":"1px dashed #808080"};
          if(this.feedbackDom == null){
              var button=COM.util.HTMLUtil.createELement('<button type="button" class="btn"></button>');
              this.feedbackDom=button[0];
          }
          if(height>0&&width>0){
              css.height=height;
              css.width=width;
          }else{
              css.minHeight=30;
              css.minWidth=60;
          }
            COM.util.HTMLUtil.getJqueryDOM(this.feedbackDom).css(css);
            this.domElement.children[0].appendChild(this.feedbackDom);
            return COM.util.HTMLUtil.getBounds(this.feedbackDom);
        },
        eraseFeedback:function () {
            if(COM.util.HTMLUtil.hasChild(this.domElement, this.feedbackDom)) {
                this.domElement.children[0].removeChild(this.feedbackDom);
            }
        },
        layoutChild : function(child){
            var childDom = child.getDomElement();
            var layoutData = child.getLayoutData();
            if(layoutData){
                var css = {};
                if(layoutData.x >= 0) {
                    css.width = layoutData.x;
                }
                if(layoutData.y >= 0) {
                    css.height = layoutData.y;
                }
                $(childDom).css(css);
            }
        }
    });/**
 * Created by zhangwenlei on 2017/5/9.
 */
// (function(){
ADF.policy.ButtonGroupPolicy = function(){
    ADF.policy.ButtonGroupPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.ButtonGroupPolicy, COM.gef.XYLayoutEditPolicy, {
    showLayoutTargetFeedback:function (request) {
        var RequestConstants = COM.gef.RequestConstants;
        if (RequestConstants.REQ_CREATE == (request.getType())){
            var model = request.getNewObject();
            if(model instanceof ADF.model.ButtonModel) {
                var bounds = this.getHost().getFigure().getWidget().showFeedback(model.getLayoutData().height,model.getLayoutData().width);
                model.getLayoutData().x = bounds.x;
                model.getLayoutData().y = bounds.y;
                model.getLayoutData().height = bounds.height;
                model.getLayoutData().width=bounds.width;
            }
        }
    },
    eraseLayoutTargetFeedback: function(request) {
        this.getHost().getFigure().getWidget().eraseFeedback();
    },
    createChangeConstraintCommand: function(request, child, rect){
        if(request.getResizeDirection() != COM.draw2d.PositionConstants.EAST) {
            return COM.gef.Command.UNEXECUTABLE_COMMAND;
        }
        if(rect.height > this.getHost().getFigure().getSize().height) {
            return COM.gef.Command.UNEXECUTABLE_COMMAND;
        }
        if(rect.width > this.getHost().getFigure().getSize().width) {
            return COM.gef.Command.UNEXECUTABLE_COMMAND;
        }

        var model = child.getModel();
        return COM.gef.Command.createCommand({
            label: 'change bounds',
            execute: function(){
                this.old = model.getLayoutData();
                model.setLayoutData(rect);
            },
            undo: function(){
                model.setLayoutData(this.old);
            }
        });

    },
    getCreateCommand: function(request){
        if(!(request.getNewObject() instanceof ADF.model.ButtonModel)) {
            return COM.gef.Command.UNEXECUTABLE_COMMAND;
        }
        return COM.gef.Command.createCommand({
            label: 'create child',
            child: request.getNewObject(),
            parent: this.getHost().getModel(),
            figure: this.getHost().getFigure(),
            execute: function(){
                this.parent.addChild(this.child);
                this.child.setLayoutData(new COM.draw2d.Point(63,33));
            },
            undo: function(){
                this.parent.removeChild(this.child);
            }
        });
    },
    createAddCommand: function(request, child, rect) {
        if(!(child.getModel() instanceof ADF.model.ButtonForGroupModel)) {
            return COM.gef.Command.UNEXECUTABLE_COMMAND;
        }
        var command = new COM.gef.CompoundCommand(), deleteCommand = null, addCommand = null;
        deleteCommand = COM.gef.Command.createCommand({
            label: 'delete model',
            parentModel: child.getParent().getModel(),
            childModel:child.getModel(),
            oldBounds: child.getModel().getLayoutData(),
            execute: function(){
                this.parentModel.removeChild(this.childModel);
            },
            undo: function(){
                this.parentModel.addChild(this.childModel);
                this.childModel.setLayoutData(this.oldBounds);
            }
        });
        addCommand = COM.gef.Command.createCommand({
            label: 'add model',
            parentModel: this.getHost().getModel(),
            childModel:child.getModel(),
            execute: function(){
                this.parentModel.addChild(this.childModel);
                this.childModel.setLayoutData(rect);
            },
            undo: function(){
                this.parentModel.removeChild(this.childModel);
            }
        });
        command.add(deleteCommand);
        command.add(addCommand);
        return command.unwrap();
    },
    getConstraintFor: function(request, child) {
        var rectangle = new COM.draw2d.Rectangle(),
            childBoundsCopy = child.getModel().getBounds().copy(),
            hostModel = this.getHost().getModel(),
            copy = hostModel.getBounds().copy(),
            hostFigure = this.getHost().getFigure(),
            childFigure = child.getFigure(),
            moveData = request.getMoveDelta();
        hostFigure.translateToAbsolute(copy);
        childFigure.translateToAbsolute(childBoundsCopy);
        var relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x + moveData.x - copy.x  , childBoundsCopy.y + moveData.y - copy.y);
        rectangle.setLocation(relativeLoaction);
        rectangle.setSize(child.getFigure().getLayoutData().getSize());
        return rectangle;
    }
});
/**
 * Created by zhangwenlei on 2017/5/9.
 */
    ADF.figure.ButtonGroupFigure = function() {
        ADF.figure.ButtonGroupFigure.superclass.constructor.call(this);
        this.setLayoutManager(new COM.draw2d.XYLayout());
    };

    COM.util.defineClass(ADF.figure.ButtonGroupFigure, AGEF.CompositeFigure, {
        paintChildren: function(graphics){
            ADF.figure.ButtonGroupFigure.superclass.paintChildren.call(this, graphics);
        },
        useLocalCoordinates: function() {
            return true;
        },
        getPreferredSize: function() {
            var widgetBounds = this.getWidget().getBounds();
            var size = new COM.draw2d.Dimension(widgetBounds.width, widgetBounds.height);
            this.prefSize = size;
            return this.prefSize;
        },
        add: function(child, constraint, index){
            var newConstraint = this.addChildWidget(child, constraint, index);
            if(newConstraint) {
                constraint = newConstraint;
                constraint.setSize(-1, -1);
            }
            AGEF.CompositeFigure.superclass.add.call(this, child, constraint, index);
        }
    });/**
 * Created by zhangwenlei on 2017/5/9.
 */
ADF.model.ButtonGroupModel = function(isGrid) {
    ADF.model.ButtonGroupModel.superclass.constructor.call(this);
    this.isGrid = isGrid;
};

COM.util.defineClass(ADF.model.ButtonGroupModel, ADF.model.CompositeModel, {
    _getModelType: function(){
        return "ADF.model.ButtonGroupModel";
    },
    _getName : function(){
        return 'buttonGroup';  
    },
    _initChildLayoutData : function(child){
        var layoutdata=new COM.draw2d.Point();
        COM.util.ObjUtil.copyProperty(layoutdata,child.getLayoutData());
        child.setLayoutData(layoutdata);
    },

    _initChildLayoutDataEditorType : function(descriptor){
        descriptor.setEditorType("baseProperty.ButtonGroupLayoutDataEditor");
    },
    _getShowText : function(){
        return "ButtonGroup";
    }
});/**
 * Created by zhangwenlei on 2017/5/9.
 */

ADF.control.ButtonGroup = function() {
    ADF.control.ButtonGroup.superclass.constructor.call(this);
};
COM.util.defineClass(ADF.control.ButtonGroup, ADF.CompositeDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var buttonGroupFigure = new ADF.figure.ButtonGroupFigure();
                var buttonGroup = this.getWidgetFactory().createControl(this.getModel());
                buttonGroupFigure.setWidget(buttonGroup);
                return buttonGroupFigure;
            },
            createEditPolicies: function() {
                editpart.superclass.createEditPolicies.call(this);
                this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.ButtonGroupPolicy());
            },
            getModelChildren: function(){
                var composite = this.getModel();
                return composite.getChildren();
            },
            refreshVisuals: function( ) {
                var widgetBounds = this.getFigure().getWidget().getBounds();
                this.getFigure().setPreferredSize(new COM.draw2d.Dimension(widgetBounds.width, widgetBounds.height));
            },
            updateConstraint: function(bounds) {
                var constrain = new COM.draw2d.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                this.getParent().getFigure().setConstraint(this.getFigure(), constrain);
            },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                var prop = evt.getPropertyName();
                if("children" == prop) {
                    this.refreshChildren();
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.ButtonGroupModel;
    },

    getDomControl : function(){
        return ADF.domControl.ButtonGroup;
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.layoutData = ADF.layoutData || {};
ADF.layoutData.ColData = function(md) {
    ADF.layoutData.ColData.superclass.constructor.call(this);
    this.xs = null;
    this.sm = null;
    this.md = md || 1;
    this.lg = null;
    this.height = null;
};

COM.util.defineClass(ADF.layoutData.ColData, Object, {

    setXs : function(count){
        this.xs = count;
    },

    setSm : function(count){
        this.sm = count;
    },

    setMd : function(count){
        this.md = count;
    },

    setLg : function(count){
        this.lg = count;
    },

    setHeight : function(height){
        this.height = height;
    },

    getXs : function(){
        return this.xs;
    },

    getSm : function(){
        return this.sm;
    },

    getMd : function(){
        return this.md;
    },

    getLg : function(){
        return this.lg;
    },

    getHeight : function(){
        return this.height;
    },

    getClassStr : function(){
        var strs = [];
        var names = ["xs", "sm", "md", "lg"];
        for (var i = 0; i < names.length; i++) {
            var name = names[i];
            var val = this[name];
            if(val){
                strs.push("col-" + name + "-" + val);
            }
        }
        return strs.join(" ");
    },

    clone : function(){
        var nd = new ADF.layoutData.ColData();
        nd.setHeight(this.getHeight());
        nd.setLg(this.getLg());
        nd.setSm(this.getSm());
        nd.setMd(this.getMd());
        nd.setXs(this.getXs());
        return nd;
    },

    equals : function(data){
        return data ? 
        this.xs == data.xs 
        && this.sm == data.sm
        && this.md == data.md 
        && this.lg == data.lg 
        && this.height == data.height
        : false;
    }
});
/**
 * Created by xiongshilin on 2017/4/14.
 */
ADF.domControl.BootstrapRow = function(parent) {
    ADF.domControl.BootstrapRow.superclass.constructor.call(this, parent);
    this.feedbackDom = null;
};

COM.util.defineClass(ADF.domControl.BootstrapRow, ADF.domControl.Composite, {
    setHeight: function(height) {
        COM.util.HTMLUtil.setElementMinHeight(this.domElement, height);
    },
    getLabel: function(){
        return "Row";
    },
    appendDomChild: function(child) {
        this.getDomElement().children[0].appendChild(child);
    },
    removeDomChild: function(child) {
        this.getDomElement().children[0].removeChild(child);
    },
    _getDomElement: function(model) {
        var rowWrap = this.createRowWrap(model);
        var row = this.createRow(model);
        rowWrap.append(row);
        this.domElement = rowWrap[0];
        return this.domElement;
    },
    createRowWrap: function(model) {
        var height = model.getLayoutData();
        var rowWrap = COM.util.HTMLUtil.createELement('<div class="bootstrapWrap rowWrap adf_wrapper"></div>');
        var css = {"display":"block",
            "position":"relative"
        };
        rowWrap.css(css);
        return rowWrap;
    },
    createRow: function(model) {
        var row = COM.util.HTMLUtil.createELement('<div class="row"></div>');
        var css = {"position":"relative",
            "overflow":"visible"
            /*"background-color":"rgba(89,89,89,1)"*/};
        //css.minHeight = 60;
        row.css(css);
        return row;
    },
    showFeedback: function(model) {
        var css = {};
        if(this.feedbackDom == null) {
            var feedBackCol = COM.util.HTMLUtil.createELement('<div class="col-md-1"></div>');
            css = {"position":"relative", "overflow":"visible", "background":"none", "border":"1px dashed #808080"};
            feedBackCol.css(css);
            this.feedbackDom = feedBackCol[0];
        } else {
            $(this.feedbackDom).attr('class', "col-md-1");
        }
        this.feedbackDom.style.height = "40px";
        this.domElement.children[0].appendChild(this.feedbackDom);
    },
    eraseFeedback: function() {
        if(COM.util.HTMLUtil.hasChild(this.domElement, this.feedbackDom)) {
            this.domElement.children[0].removeChild(this.feedbackDom);
        }
    },
    layoutChild : function(child){
        var childDom = child.getDomElement();
        var layoutData = child.getLayoutData();
        if(layoutData){
            var css = {"display":"block", "height":layoutData.getHeight()};
            $(childDom).css(css);
            (function removeOldClass(){
                var old = $(childDom).attr("boot-class");
                if(old){
                    var olds = old.split(" ");
                    olds.forEach(function(clazz) {
                        $(childDom).removeClass(clazz);
                    }, this);
                }
            })();
            (function addNewClass(){
                var newCls = layoutData.getClassStr();
                $(childDom).attr("boot-class", newCls);
                if(newCls){
                    var newClszz = newCls.split(" ");
                    newClszz.forEach(function(clazz) {
                        $(childDom).addClass(clazz);
                    }, this);
                }
            })();
        }
        child._afterLayout();
    },
    _childLayoutChanged : function(child){
        var childDom = child.getDomElement();
        return !(child.getLayoutData().getClassStr() == $(childDom).attr("boot-class") && child.getLayoutData().getHeight() == parseInt(child.getDomElement().style.height, 10));
    }
});
/**
 * Created by xiongshilin on 2017/4/14.
 */
ADF.domControl.BootstrapContainer = function(parent) {
    ADF.domControl.BootstrapContainer.superclass.constructor.call(this, parent);
    this.feedbackDom = null;
};

COM.util.defineClass(ADF.domControl.BootstrapContainer, ADF.domControl.Composite, {
    getLabel: function(){
        return "Container";
    },
    appendDomChild: function(child) {
        this.getDomElement().children[0].appendChild(child);
        //this.getDomElement().appendChild(child);
    },
    removeDomChild: function(child) {
        this.getDomElement().children[0].removeChild(child);
        //this.getDomElement().removeChild(child);
    },
    _getDomElement: function(model) {
        var containerWrap = this.createContainerWrap(model);
        var container = this.createContainer(model);
        containerWrap.append(container);
        this.domElement = containerWrap[0];
        return this.domElement;
    },
    createContainerWrap: function(model) {
        var containerWrap = COM.util.HTMLUtil.createELement('<div class="bootstrapWrap containerWrap adf_wrapper"></div>');
        return containerWrap;
    },
    createContainer: function(model) {
        var container = COM.util.HTMLUtil.createELement('<div class="container"></div>');
        var css = {"position":"relative",
            "overflow":"visible",
            "width":"100%",
            /*"background-color":"rgba(89,89,89,1)"*/};
        css.minHeight = 100;
        container.css(css);
        return container;
    },
    showFeedback: function(height) {
        var css = {"position":"relative", "overflow":"visible", "border":"1px dashed #808080"};
        if(this.feedbackDom == null) {
            var row = COM.util.HTMLUtil.createELement('<div class="bootstrapWrap rowWrap adf_wrapper"><div class="row"></div></div>');
            this.feedbackDom = row[0];
        }
        if(height>0) {
            css.height = height;
        } else {
            css.minHeight = 60;
        }
        COM.util.HTMLUtil.getJqueryDOM(this.feedbackDom).css(css);
        this.domElement.children[0].appendChild(this.feedbackDom);
        return COM.util.HTMLUtil.getBounds(this.feedbackDom);
    },
    eraseFeedback: function() {
        if(COM.util.HTMLUtil.hasChild(this.domElement, this.feedbackDom)) {
            this.domElement.children[0].removeChild(this.feedbackDom);
        }
    },
    layoutChild : function(child){
        var childDom = child.getDomElement();
        var layoutData = child.getLayoutData();
        var css = {"display":"block", "height":layoutData};
        $(childDom).css(css);
        child._afterLayout();
    },
    _childLayoutChanged : function(child){
        return child.getLayoutData() != child.getOldLayoutData();
    }
});
/**
 * Created by xiongshilin on 2017/4/13.
 */
(function(){
    ADF.figure.BootstrapRowFigure = function() {
        ADF.figure.BootstrapRowFigure.superclass.constructor.call(this);
        this.setLayoutManager(new COM.draw2d.XYLayout());
    };

    COM.util.defineClass(ADF.figure.BootstrapRowFigure, AGEF.CompositeFigure, {
        paintChildren: function(graphics){
            ADF.figure.BootstrapRowFigure.superclass.paintChildren.call(this, graphics);
        },
        useLocalCoordinates: function() {
            return true;
        },
        getPreferredSize: function() {
            var widgetBounds = this.getWidget().getBounds();
            var size = new COM.draw2d.Dimension(widgetBounds.width, widgetBounds.height);
            this.prefSize = size;
            return this.prefSize;
        },
        add: function(child, constraint, index){
            var newConstraint = this.addChildWidget(child, constraint, index);
            if(newConstraint) {
                constraint = newConstraint;
                constraint.setSize(-1, -1);
            }
            AGEF.CompositeFigure.superclass.add.call(this, child, constraint, index);
        }
    });
})();
/**
 * Created by xiongshilin on 2017/4/13.
 */
(function(){
    ADF.figure.BootstrapContainerFigure = function() {
        ADF.figure.BootstrapContainerFigure.superclass.constructor.call(this);
        this.setLayoutManager(new COM.draw2d.XYLayout());
    };

    COM.util.defineClass(ADF.figure.BootstrapContainerFigure, AGEF.CompositeFigure, {
        paintChildren: function(graphics){
            ADF.figure.BootstrapContainerFigure.superclass.paintChildren.call(this, graphics);
        },
        initEventListener: function() {
            this.addMouseMotionListener({mouseEntered: function(event, source) {
                var widget = this.getWidget();
                COM.util.HTMLUtil.setStyle(widget.getDomElement(), {"background-color":"rgba(245,245,245,0.5)"});//#f8f8f8
            }.bind(this),mouseExited: function(event, source) {
                var widget = this.getWidget();
                COM.util.HTMLUtil.setStyle(widget.getDomElement(), {"background":"none"});
            }.bind(this)
            });
        },
        add: function(child, constraint, index){
            var newConstraint = this.addChildWidget(child, constraint, index);
            if(newConstraint) {
                constraint = newConstraint;
                constraint.setSize(-1, -1);
            }
            AGEF.CompositeFigure.superclass.add.call(this, child, constraint, index);
        },
        useLocalCoordinates: function() {
            return true;
        }
    });
})();
/**
 * Created by xiongshilin on 2017/4/13.
 */
(function(){
    ADF.model.BootstrapRowModel = function() {
        ADF.model.BootstrapRowModel.superclass.constructor.call(this);
    };
    COM.util.defineClass(ADF.model.BootstrapRowModel, ADF.model.CompositeModel, {
        _getModelType: function(){
            return "ADF.model.BootstrapRowModel";
        },
        _getName : function(){
            return 'row';  
        },
        _getShowText : function(){
            return "BootstrapRow";
        },
        _initChildLayoutData : function(child){
            var ld = new ADF.layoutData.ColData();
            ld.setHeight(36);
            child.setLayoutData(ld);
        },

        _initChildLayoutDataEditorType : function(descriptor){
            descriptor.setEditorType("baseProperty.RowLayoutDataEditor");
        },
    });
})();
/**
 * Created by xiongshilin on 2017/4/13.
 */
(function(){
    ADF.model.BootstrapContainerModel = function() {
        ADF.model.BootstrapContainerModel.superclass.constructor.call(this);
    };
    COM.util.defineClass(ADF.model.BootstrapContainerModel, ADF.model.CompositeModel, {
        
        _getModelType: function(){
            return "ADF.model.BootstrapContainerModel";
        },
        _getName : function(){
            return 'container';  
        },
        _getShowText : function(){
            return "BootstrapContainer";
        },
        _initChildLayoutData : function(child){
            child.setLayoutData(60);
        },

        _initChildLayoutDataEditorType : function(descriptor){
            descriptor.setEditorType("baseProperty.ContainerLayoutDataEditor");
        },
    });
})();
(function(){
  ADF.policy.SouthResizePolicy = function(){
    ADF.policy.SouthResizePolicy.superclass.constructor.call(this);
  }

  //static properties
  COM.util.defineClass(ADF.policy.SouthResizePolicy, COM.gef.ResizableEditPolicy, {
    createSelectionHandles: function() {
        if (this.resizeDirections == COM.draw2d.PositionConstants.NONE) {
            // non resizable, so delegate to super implementation
            return COM.gef.ResizableEditPolicy.superclass.createSelectionHandles.call(this);
        }

        // resizable in at least one direction
        var list = [];
        this.createMoveHandle(list);
        this.createResizeHandle(list, COM.draw2d.PositionConstants.SOUTH);
        return list;
    }
  });

})();

(function(){
  ADF.policy.RowLayoutPolicy = function(){
    ADF.policy.RowLayoutPolicy.superclass.constructor.call(this);
  }

  //static properties
  COM.util.defineClass(ADF.policy.RowLayoutPolicy, COM.gef.XYLayoutEditPolicy, {
    showLayoutTargetFeedback: function(request) {
      //展示目标反馈
      var RequestConstants = COM.gef.RequestConstants;
      if (RequestConstants.REQ_CREATE == request.getType()){
        var model = request.getNewObject();
        // if(model instanceof ADF.model.BootstrapColumnModel) {
          this.getHost().getFigure().getWidget().showFeedback(model);
        // }
      } else if(RequestConstants.REQ_ADD == request.getType()) {
        var editParts = request.getEditParts();
        var model = editParts[0].getModel();
        // if(model instanceof ADF.model.BootstrapColumnModel) {
          this.getHost().getFigure().getWidget().showFeedback(model);
        // }
      }
    },
    eraseLayoutTargetFeedback: function(request) {
      //擦除目标反馈
      this.getHost().getFigure().getWidget().eraseFeedback();
    },
    createChangeConstraintCommand: function(request, child, rect){
      if(request.getResizeDirection() != COM.draw2d.PositionConstants.SOUTH) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }

      var model = child.getModel();
      return COM.gef.Command.createCommand({
        label: 'change bounds',
        execute: function(){
          this.old = model.getLayoutData();
          var nd = model.getLayoutData().clone();
          nd.setHeight(rect.height);
          model.setLayoutData(nd);
          // child.getFigure().revalidate();//TODO 没生效
        },
        undo: function(){
          model.setLayoutData(this.old);
        }
      });
    },
    getCreateCommand: function(request){
      return COM.gef.Command.createCommand({
        label: 'create child',
        child: request.getNewObject(),
        parent: this.getHost().getModel(),
        figure: this.getHost().getFigure(),
        execute: function(){//
          var models;
          if(this.child instanceof ADF.model.CompoundModel){
            models = this.child.getModels();
          }else{
            models = [this.child];
          }
          for (var i = 0; i < models.length; i++) {
            var model = models[i];
            this.parent.addChild(model);
          }
        },
        undo: function(){
          var models;
          if(this.child instanceof ADF.model.CompoundModel){
            models = this.child.getModels();
          }else{
            models = [this.child];
          }
          for (var i = 0; i < models.length; i++) {
            var model = models[i];
            this.parent.removeChild(model);
          }
        }
      });
    },
    createAddCommand: function(request, child, rect) {
      //TODO
      if(!(child.getModel() instanceof ADF.model.BootstrapColumnModel)) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }
      var command = new COM.gef.CompoundCommand(), deleteCommand = null, addCommand = null;
      deleteCommand = COM.gef.Command.createCommand({
        label: 'delete model',
        parentModel: child.getParent().getModel(),
        childModel:child.getModel(),
        oldBounds: child.getModel().getLayoutData(),
        execute: function(){
          this.parentModel.removeChild(this.childModel);
        },
        undo: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(this.oldBounds);
        }
      });
      addCommand = COM.gef.Command.createCommand({
        label: 'add model',
        parentModel: this.getHost().getModel(),
        childModel:child.getModel(),
        execute: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setBounds(rect);
        },
        undo: function(){
          this.parentModel.removeChild(this.childModel);
        }
      });
      command.add(deleteCommand);
      command.add(addCommand);
      return command.unwrap();
    },
    getConstraintFor: function(request, child) {
      //TODO
      var rectangle = new COM.draw2d.Rectangle(), childBoundsCopy = child.getModel().getBounds().copy(),
          hostModel = this.getHost().getModel(), copy = hostModel.getBounds().copy(),
          hostFigure = this.getHost().getFigure(), childFigure = child.getFigure(), moveData = request.getMoveDelta();
      hostFigure.translateToAbsolute(copy);
      childFigure.translateToAbsolute(childBoundsCopy);
      var relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x + moveData.x - copy.x  , childBoundsCopy.y + moveData.y - copy.y);
      rectangle.setLocation(relativeLoaction);
      rectangle.setSize(child.getFigure().getBounds().getSize());
      return rectangle;
    }
    // ,
    // createChildEditPolicy : function(child){
    //   return new ADF.policy.SouthResizePolicy();
    // }
  });

})();

(function(){
  ADF.policy.BootstrapContainerLayoutPolicy = function(){
    ADF.policy.BootstrapContainerLayoutPolicy.superclass.constructor.call(this);
  }

  //static properties
  COM.util.defineClass(ADF.policy.BootstrapContainerLayoutPolicy, COM.gef.XYLayoutEditPolicy, {
    /*createChildEditPolicy: function(child) {

    },*/
    showLayoutTargetFeedback: function(request) {
      //展示目标反馈
      var RequestConstants = COM.gef.RequestConstants;
      if (RequestConstants.REQ_CREATE == (request.getType())){
        var model = request.getNewObject();
        if(model instanceof ADF.model.BootstrapRowModel) {
          this.getHost().getFigure().getWidget().showFeedback(model.getLayoutData());
        }
      }
    },
    eraseLayoutTargetFeedback: function(request) {
      //擦除目标反馈
      this.getHost().getFigure().getWidget().eraseFeedback();
    },
    createChangeConstraintCommand: function(request, child, rect){
      //COM.draw2d.PositionConstants WEST EAST
      if(request.getResizeDirection() != COM.draw2d.PositionConstants.SOUTH) {
          return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }
      if(rect.height > this.getHost().getFigure().getSize().height) {
          return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }
      var model = child.getModel();
      return COM.gef.Command.createCommand({
        label: 'change bounds',
        execute: function(){
          this.old = model.getLayoutData();
          model.setLayoutData(rect.height);
        },
        undo: function(){
          model.setLayoutData(this.old);
        }
      });

    },
    getCreateCommand: function(request){
      if(!(request.getNewObject() instanceof ADF.model.BootstrapRowModel)) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }
      return COM.gef.Command.createCommand({
        label: 'create child',
        child: request.getNewObject(),
        parent: this.getHost().getModel(),
        figure: this.getHost().getFigure(),
        execute: function(){//
          this.parent.addChild(this.child);
        },
        undo: function(){
          this.parent.removeChild(this.child);
        }
      });
    },
    createAddCommand: function(request, child, height) {
      if(!(child.getModel() instanceof ADF.model.BootstrapRowModel)) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }
      var command = new COM.gef.CompoundCommand(), deleteCommand = null, addCommand = null;
      deleteCommand = COM.gef.Command.createCommand({
        label: 'delete model',
        parentModel: child.getParent().getModel(),
        childModel:child.getModel(),
        oldBounds: child.getModel().getLayoutData(),
        execute: function(){
          this.parentModel.removeChild(this.childModel);
        },
        undo: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(this.oldBounds);
        }
      });
      addCommand = COM.gef.Command.createCommand({
        label: 'add model',
        parentModel: this.getHost().getModel(),
        childModel:child.getModel(),
        execute: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(height);
        },
        undo: function(){
          this.parentModel.removeChild(this.childModel);
        }
      });
      command.add(deleteCommand);
      command.add(addCommand);
      return command.unwrap();
    },
    getConstraintFor: function(request, child) {
      var ld = child.getModel().getLayoutData();
      if(Object.prototype.toString.call(ld) == "[object Number]"){
        return ld;
      }
      return 60;
    }
    // ,
    // createChildEditPolicy : function(child){
    //   return new ADF.policy.SouthResizePolicy();
    // }
  });

})();

/**
 * Created by xiongshilin on 2017/4/14.
 */
(function(){
    ADF.editpart.BootstrapRowEditPart = function(){
        ADF.editpart.BootstrapRowEditPart.superclass.constructor.call(this);
    }
    COM.util.defineClass(ADF.editpart.BootstrapRowEditPart, ADF.editpart.CompositeEditpart,{
        _createFigure: function(){
            var figure = new ADF.figure.BootstrapRowFigure();
            var rowControl = this.getWidgetFactory().createControl(this.getModel());
            figure.setWidget(rowControl);
            return figure;
        },

        createEditPolicies: function(){
            ADF.editpart.BootstrapRowEditPart.superclass.createEditPolicies.call(this);
            this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.RowLayoutPolicy());
        },

        getModelChildren: function(){
            var container = this.getModel();
            return container.getChildren();
        },
        refreshVisuals: function() {
            var widgetBounds = this.getFigure().getWidget().getBounds();
            this.getFigure().setPreferredSize(new COM.draw2d.Dimension(widgetBounds.width, widgetBounds.height));
        }
    });
})();
/**
 * Created by xiongshilin on 2017/4/14.
 */
(function(){
    ADF.editpart.BootstrapContainerEditPart = function(){
        ADF.editpart.BootstrapContainerEditPart.superclass.constructor.call(this);
    }
    COM.util.defineClass(ADF.editpart.BootstrapContainerEditPart, ADF.editpart.CompositeEditpart,{
        _createFigure: function(){
            var figure = new ADF.figure.BootstrapContainerFigure();
            var containerControl = this.getWidgetFactory().createControl(this.getModel());
            figure.setWidget(containerControl);

            var border = new COM.draw2d.LineBorder(4,new COM.draw2d.Color(255,255,255,0));
            //figure.setBorder(border);
            return figure;
        },

        createEditPolicies: function(){
            ADF.editpart.BootstrapContainerEditPart.superclass.createEditPolicies.call(this);
            //this.installEditPolicy(COM.gef.EditPolicy.CONTAINER_ROLE, new COM.demo.DiagramContainerEditPolicy());
            this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.BootstrapContainerLayoutPolicy());
        },

        getModelChildren: function(){
            var children = this.getModel().getChildren();
            /*children.forEach(function(child, index, array){
                //child.setX(0);child.setY(0);
            });*/
            return children;
        },
        refreshVisuals: function(bounds) {

        },
        updateConstraint: function(bounds) {
            var constrain = new COM.draw2d.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
            this.getParent().getFigure().setConstraint(this.getFigure(), constrain);
        }
    });
})();/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.BootstrapContainer = function() {
    ADF.control.BootstrapContainer.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.BootstrapContainer, ADF.CompositeDescriptor, {

    getEditpart: function() {
        return ADF.editpart.BootstrapContainerEditPart;
    },

    getModel: function() {
        return ADF.model.BootstrapContainerModel;
    },

    getDomControl : function(){
        return ADF.domControl.BootstrapContainer;
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.BootstrapRow = function() {
    ADF.control.BootstrapRow.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.BootstrapRow, ADF.CompositeDescriptor, {

    getEditpart: function() {
        return ADF.editpart.BootstrapRowEditPart;
    },

    getModel: function() {
        return ADF.model.BootstrapRowModel;
    },

    getDomControl : function(){
        return ADF.domControl.BootstrapRow;
    }

});
(function(){

    ADF.domControl.XYComposite = function(parent) {
        ADF.domControl.XYComposite.superclass.constructor.call(this, parent);
    };

    COM.util.defineClass(ADF.domControl.XYComposite, ADF.domControl.Composite, {
        getLabel: function(){
            return "XYComposite";
        },
        appendDomChild: function(child) {
            this.getDomElement().appendChild(child);
        },
        removeDomChild: function(child) {
            this.getDomElement().removeChild(child);
        },
        _getDomElement: function(model) {
            var composite = COM.util.HTMLUtil.createELement('<div class="adf_xy_composite"></div>');
            this.domElement = composite[0];
            if(model.isGrid) {
                this.createGridLine(this.domElement);
            }
            return this.domElement;
        },
        createGridLine: function(dom) {
            var svg = COM.util.HTMLUtil.createELement('<svg xmlns="http://www.w3.org/2000/svg" id="main" version="1.1" style="position:absolute" width="100%" height="100%"></svg>');
            for(var i=1; i< 200; i++) {
                var x = i*15 - 0.5;
                var hline = COM.util.HTMLUtil.createELement('<line x1='+x+' y1="0" x2='+x+' y2="100%" style="stroke:rgba(120,120,120,0.3);stroke-width:1;stroke-dasharray:1;"/>');
                var vline = COM.util.HTMLUtil.createELement('<line x1="0" y1='+x+' x2="100%" y2='+x+' style="stroke:rgba(120,120,120,0.3);stroke-width:1;stroke-dasharray:1;"/>');
                svg.append(hline);
                svg.append(vline);
            }
            svg.html(svg.html());
            dom.appendChild(svg[0]);
        },
        layoutChild : function(child){
            var childDom = child.getDomElement();
            var layoutData = child.getLayoutData();
            if(layoutData){
                var css = {"display":"block", "position":"absolute", "left":layoutData.x + 'px', "top":layoutData.y + 'px'};
                if(layoutData.width >= 0) {
                    css.width = layoutData.width + 'px';
                }
                if(layoutData.height >= 0) {
                    css.height = layoutData.height + 'px';
                }
                $(childDom).css(css);
            }
            child._afterLayout();
        }
    });
})();
ADF.policy.XYCompositeLayoutPolicy = function(){
    ADF.policy.XYCompositeLayoutPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.XYCompositeLayoutPolicy, COM.gef.XYLayoutEditPolicy, {
    createChangeConstraintCommand: function(request, child, rect){
      var model = child.getModel(),
          parentFigure = child.parent.getFigure().getBounds();
      if(rect.width < 30 || rect.height < 30) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }

      return COM.gef.Command.createCommand({
        label: 'change bounds',
        execute: function(){
          this.old = model.getLayoutData();
          var boundWidth = parentFigure.width - rect.width,
              boundHeight = parentFigure.height - rect.height;
          if((rect.x > 0 &&rect.x < boundWidth) && (rect.y > 0 &&rect.y < boundHeight)){
              model.setLayoutData(rect);
          }else{
              model.setLayoutData(this.old);
          }
        },
        undo: function(){
          model.setLayoutData(this.old);
        }
      });

    },
    getCreateCommand: function(request){
      return COM.gef.Command.createCommand({
        label: 'create child',
        child: request.getNewObject(),
        parent: this.getHost().getModel(),
        figure: this.getHost().getFigure(),
        execute: function(){
          var models;
          if(this.child instanceof ADF.model.CompoundModel){
            models = this.child.getModels();
          }else{
            models = [this.child];
          }
          var copy = this.parent.getLayoutData().copy();
          this.figure.translateToAbsolute(copy);
          var relativeLoaction = new COM.draw2d.Point(request.location.x - copy.x, request.location.y - copy.y);
          var rel;
          for (var i = 0; i < models.length; i++) {
            var model = models[i];
            if(i > 0){
              relativeLoaction.x = relativeLoaction.x + models[i - 1].getLayoutData().width - 1;
            }
            this.parent.addChild(model);
            var bounds = new COM.draw2d.Rectangle();
            bounds.width = 63;
            bounds.height = 33;
            bounds.setLocation(relativeLoaction);
            model.setLayoutData(bounds);
          }
        },
        undo: function(){
          var models;
          if(this.child instanceof ADF.model.CompoundModel){
            models = this.child.getModels();
          }else{
            models = [this.child];
          }
          for (var i = 0; i < models.length; i++) {
            var model = models[i];
            this.parent.removeChild(model);
          }
        }
      });
    },
    createAddCommand: function(request, child, rect) {
      var command = new COM.gef.CompoundCommand(), deleteCommand = null, addCommand = null;
      deleteCommand = COM.gef.Command.createCommand({
        label: 'delete model',
        parentModel: child.getParent().getModel(),
        childModel:child.getModel(),
        oldBounds: child.getModel().getLayoutData(),
        execute: function(){
          this.parentModel.removeChild(this.childModel);
        },
        undo: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(this.oldBounds);
        }
      });
      addCommand = COM.gef.Command.createCommand({
        label: 'add model',
        parentModel: this.getHost().getModel(),
        childModel:child.getModel(),
        execute: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(rect);
        },
        undo: function(){
          this.parentModel.removeChild(this.childModel);
        }
      });
      command.add(deleteCommand);
      command.add(addCommand);
      return command.unwrap();
    },
    getConstraintFor: function(request, child) {
      var rectangle = new COM.draw2d.Rectangle(), childBoundsCopy = child.getModel().getLayoutData().copy(),
          hostModel = this.getHost().getModel(), copy = hostModel.getLayoutData().copy(),
          hostFigure = this.getHost().getFigure(), childFigure = child.getFigure(), moveData = request.getMoveDelta();
      hostFigure.translateToAbsolute(copy);
      childFigure.translateToAbsolute(childBoundsCopy);
      var relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x + moveData.x - copy.x  , childBoundsCopy.y + moveData.y - copy.y);
      rectangle.setLocation(relativeLoaction);
      rectangle.setSize(child.getFigure().getLayoutData().getSize());
      return rectangle;
    }
});(function(){
    ADF.figure.XYCompositeFigure = function() {
        ADF.figure.XYCompositeFigure.superclass.constructor.call(this);
        this.setLayoutManager(new COM.draw2d.XYLayout());
    };

    COM.util.defineClass(ADF.figure.XYCompositeFigure, AGEF.CompositeFigure, {
        paintChildren: function(graphics){
            ADF.figure.XYCompositeFigure.superclass.paintChildren.call(this, graphics);
        },
        useLocalCoordinates: function() {
            return true;
        }
    });
})();
ADF.model.XYCompositeModel = function(isGrid) {
    ADF.model.XYCompositeModel.superclass.constructor.call(this);
    this.isGrid = isGrid;
};

COM.util.defineClass(ADF.model.XYCompositeModel, ADF.model.CompositeModel, {
    _getModelType: function(){
        return "ADF.model.XYCompositeModel";
    },
    _getName : function(){
        return 'xyComposite';  
    },
    _getShowText : function(){
        return "XYComposite";
    }
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.XYComposite = function() {
    ADF.control.XYComposite.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.XYComposite, ADF.CompositeDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.CompositeEditpart, {
            _createFigure: function() {
                var xyCompositeFigure = new ADF.figure.XYCompositeFigure();
                var xyComposite = this.getWidgetFactory().createControl(this.getModel());
                xyCompositeFigure.setWidget(xyComposite);
                return xyCompositeFigure;
            },
            createEditPolicies: function() {
                editpart.superclass.createEditPolicies.call(this);
                this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.XYCompositeLayoutPolicy());
                this.installEditPolicy(COM.gef.EditPolicy.SELECTION_FEEDBACK_ROLE, new ADF.policy.SnapPolicy());
            },
            getModelChildren: function(){
                var composite = this.getModel();
                return composite.getChildren();
            },
            refreshChildren: AGEF.functions.editPartRefreshChildren,
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.XYCompositeModel;
    },

    getDomControl : function(){
        return ADF.domControl.XYComposite;
    }

});
ADF.domControl.Datetime = function(parent) {
    ADF.domControl.Datetime.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Datetime, ADF.domControl.BaseControl, {
    getLabel: function() {
        return "Datetime";
    },
    setADFFormat: function(format) {
        if (format) {
            $(this.domElement).attr({"ADFFormat":format,"placeholder":format});
        } else {
            $(this.domElement).removeAttr("ADFFormat").removeAttr("placeholder");
        }
    },
    _getDomElement: function(model) {
        var Datetime = COM.util.HTMLUtil.createELement('<input class="laydate-icon"/>');
        return Datetime[0];
    }

});ADF.policy.DatetimeComponentEditPartPolicy = function() {
    ADF.policy.DatetimeComponentEditPartPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.DatetimeComponentEditPartPolicy, AGEF.ComponentEditPolicy, {

});ADF.model.DatetimeModel = function() {
    ADF.model.DatetimeModel.superclass.constructor.call(this);
};

ADF.model.DatetimeModel.PROPERTY_ADFFORMAT = "format";

COM.util.defineClass(ADF.model.DatetimeModel, ADF.model.BaseModel, {

    initModel: function() {
        ADF.model.DatetimeModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.DatetimeModel.PROPERTY_ADFFORMAT, "", "", true, "格式"));
    },
    setADFFormat: function(format) {
        this.setPropertyValue(ADF.model.DatetimeModel.PROPERTY_ADFFORMAT, format);
    },
    getADFFormat: function() {
        return this.getPropertyValue(ADF.model.DatetimeModel.PROPERTY_ADFFORMAT);
    },

    _getModelType: function() {
        return "ADF.model.DatetimeModel";
    },

    _getName : function(){
        return 'datetime';  
    },

    fillSerializedJson: function(jsonObject) {
        jsonObject[ADF.model.DatetimeModel.PROPERTY_ADFFORMAT] = this.getPropertyDescriptor(ADF.model.DatetimeModel.PROPERTY_ADFFORMAT).serialize();
    },

    _deserialize: function(jsonObject) {
        var newProp = null;

        newProp = new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.DatetimeModel.PROPERTY_ADFFORMAT]);
        this.propertyDescriptors.put(newProp.getName(), newProp);
    }
});ADF.control.Datetime = function() {
    ADF.control.Datetime.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Datetime, ADF.ControlDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var DatetimeFigure = new AGEF.WidgetFigure(this.id);
                var Datetime = this.getWidgetFactory().createControl(this.getModel());
                DatetimeFigure.setWidget(Datetime);
                return DatetimeFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new ADF.policy.DatetimeComponentEditPartPolicy());
            // },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
                    if (ADF.model.DatetimeModel.PROPERTY_ADFFORMAT == evt.getPropertyName()) {
                        this.getFigure().getWidget().setADFFormat(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.DatetimeModel;
    },

    getDomControl: function() {
        return ADF.domControl.Datetime;
    }

});ADF.layoutData = ADF.layoutData || {};
ADF.layoutData.DiagramData = function(autoSize){
    ADF.layoutData.DiagramData.superclass.constructor.call(this);
    this.autoSize = autoSize || false;
    this.width = null;
    this.height = null;
    this.x = null;
    this.y = null;
};

COM.util.defineClass(ADF.layoutData.DiagramData,Object,{

    setAutoSize:function(boolean){
        this.autoSize = boolean;
    },

    setWidth:function(count){
        this.width = count;
    },

    setHeight:function(count){
        this.height = count;
    },

    getAutoSize:function(){
        return this.autoSize;
    },

    getWidth:function(){
        return this.width;
    },

    getHeight:function(){
        return this.height;
    },

    clone:function(){
        var md = new ADF.layoutData.DiagramData();
        md.setAutoSize(this.getAutoSize());
        md.setWidth(this.getWidth());
        md.setHeight(this.getHeight());
        return md;
    },

    equals:function(data){
        return data ?
        this.autoSize == data.autoSize
        && this.width == data.width
        && this.height == data.height
        : false;
    }
})/**
 * @author zhengjiachao
 * @since 2017-3-27
 */

ADF.model.DiagramModel = function(){
    ADF.model.DiagramModel.superclass.constructor.call(this);
    this.children = [];
}

ADF.model.DiagramModel.PROPERTY_CHILDREN = "children";

COM.util.defineClass(ADF.model.DiagramModel, ADF.model.BaseModel,{
    initModel: function() {
      ADF.model.DiagramModel.superclass.initModel.call(this);
      var children = new AGEF.PropertyDescriptor(ADF.model.DiagramModel.PROPERTY_CHILDREN, []);
      this.addPropertyDescriptor(children);
    },
    addChild: function(child){
        var children = this.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN),
            newChildren = children.slice(0, children.length);
        newChildren.push(child);
        this._initChildLayoutData(child);
        this._initChildLayoutDataEditorType(child.getPropertyDescriptor(AGEF.BaseModel.PROPERTY_LAYOUTDATA));
        child.setParent(this);
        this.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
    },
    _initChildLayoutData:function(child){
        var dm = new ADF.layoutData.DiagramData();
        dm.setWidth(1180);
        dm.setHeight(850);
        dm.x = 10;
        dm.y = 10;
        child.setLayoutData(dm);
    },
    _initChildLayoutDataEditorType:function(descriptor){
        descriptor.setEditorType("baseProperty.DiagramLayoutDataEditor");
    },
    removeChild: function(child){
        var children = this.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN),
            newChildren = children.slice(0, children.length);
        child.removeParent();
        COM.util.Array.removeItem(newChildren, child);
        this.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
    },
    getChildren: function(){
        return this.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
    },

    _getModelType : function(){
        return "ADF.model.DiagramModel";
    },

    _getName : function(){
        return 'diagram';
    },

    fillSerializedJson : function(jsonObject){
        jsonObject["children"] = [];
        var children = this.getChildren();
        for(var index in children) {
            jsonObject.children.push(children[index].serialize());
        }
    },

    _deserialize: function(jsonObject) {
        var children = jsonObject["children"];
        for(var index in children) {
            var childJsonObject = COM.util.ObjUtil.parseJSON(children[index]), modelType = childJsonObject["modelType"], modelConstructor = eval("("+modelType+")");
            var childModel = new modelConstructor();
            childModel.deserialize(children[index]);
            this.addChild(childModel);
        }
    }

});

(function(){
  ADF.policy.DiagramContainerEditPolicy = function(){
    ThisClass.superclass.constructor.call(this);
  }

  var ThisClass = ADF.policy.DiagramContainerEditPolicy;

  COM.util.defineClass(ThisClass, COM.gef.ContainerEditPolicy, {
      getCreateCommand: function(request){
        return null;
      }
  });
})();

/**
 * @author jiangqifan
 * @since 2016-5-26
 */

(function(){
  ADF.policy.DiagramXYLayoutPolicy = function(){
    ThisClass.superclass.constructor.call(this);
  }

  var ThisClass = ADF.policy.DiagramXYLayoutPolicy;

  //static properties
  COM.util.defineClass(ThisClass, COM.gef.XYLayoutEditPolicy, {
    createChangeConstraintCommand: function(request, child, rect){
      var model = child.getModel(),
          parentFigure = child.parent.getFigure().getBounds();
      if(rect.width < 30 || rect.height < 30) {
        return COM.gef.Command.UNEXECUTABLE_COMMAND;
      }

      return COM.gef.Command.createCommand({
        label: 'change bounds',
        execute: function(){
          this.old = model.getLayoutData();
          // var boundWidth = parentFigure.width - rect.width - 10,
          //     boundHeight = parentFigure.height - rect.height - 10;
          // if((rect.x > 0 && rect.x < boundWidth) && (rect.y > 0 && rect.y < boundHeight)){
          //     model.setLayoutData(rect);
          // }else{
          //     console.log("禁止移除底板！！！");
          //     model.setLayoutData(this.old);
          // }
          model.setLayoutData(this.old);
        },
        undo: function(){
          model.setLayoutData(this.old);
        }
      });

    },
    getCreateCommand: function(request){
      var child = request.getNewObject(),
          parent = this.getHost().getModel(),
          children = parent.getChildren(),
          childName = child.getName();
      if(children.length == 0 &&(child instanceof ADF.model.CompositeModel) && (childName == 'xyComposite' || childName == 'container')){
          return COM.gef.Command.createCommand({
              label: 'create child',
              execute: function(){
                    var relativeLocation = new COM.draw2d.Point(10,10);
                    parent.addChild(child);
                    var bounds = new COM.draw2d.Rectangle();
                    bounds.width = 1180;
                    bounds.height = 850;
                    bounds.setLocation(relativeLocation);
                    child.setLayoutData(bounds);
              },
              undo: function(){
                  var models;
                  if(child instanceof ADF.model.CompoundModel){
                     models = child.getModels();
                  }
                  for (var i = 0; i < models.length; i++) {
                     var model = models[i];
                     parent.removeChild(model);
                  }
              }
          });
       }
    },
    /*
    createAddCommand: function(request, child, rect) {
      var command = new COM.gef.CompoundCommand(),
          deleteCommand = null,
          addCommand = null;
      deleteCommand = COM.gef.Command.createCommand({
        label: 'delete model',
        parentModel: child.getParent().getModel(),
        childModel:child.getModel(),
        oldBounds: child.getModel().getLayoutData(),
        execute: function(){
          this.parentModel.removeChild(this.childModel);
        },
        undo: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(this.oldBounds);
        }
      });
      addCommand = COM.gef.Command.createCommand({
        label: 'add model',
        parentModel: this.getHost().getModel(),
        childModel:child.getModel(),
        execute: function(){
          this.parentModel.addChild(this.childModel);
          this.childModel.setLayoutData(rect);
        },
        undo: function(){
          this.parentModel.removeChild(this.childModel);
        }
      });
      command.add(deleteCommand);
      command.add(addCommand);
      return command.unwrap();
    },
    */
    //关于鼠标移动控件时底板操作
    getConstraintFor: function(request, child) {
      var rectangle = new COM.draw2d.Rectangle(), 
          childBoundsCopy = child.getModel().getLayoutData().copy(),
          childFigure = child.getFigure(),
          moveData = request.getMoveDelta();
          //从这里开始作为判断条件，最终返回rectangle
      var cmX = childBoundsCopy.x + moveData.x,
          cmY = childBoundsCopy.y + moveData.y,
          parentWH = child.parent.getFigure().getBounds(),
          relativeLoaction;
      if((cmX > 0 && cmX < (parentWH.width - childBoundsCopy.width))&&(cmY > 0 && cmY < (parentWH.height - childBoundsCopy.width))){
          childFigure.translateToAbsolute(childBoundsCopy);
          relativeLoaction = new COM.draw2d.Point(cmX,cmY);
      }else{
          relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x,childBoundsCopy.y);
      }
      // childFigure.translateToAbsolute(childBoundsCopy);
      // var relativeLoaction = new COM.draw2d.Point(childBoundsCopy.x + moveData.x , childBoundsCopy.y + moveData.y);
      rectangle.setLocation(relativeLoaction);
      rectangle.setSize(child.getFigure().getLayoutData().getSize());
      return rectangle;
    }
  });

})();

/**
 * Created by xiongshilin on 2017/3/29.
 */
(function(){
    ADF.figure.DiagramFigure = function() {
        ADF.figure.DiagramFigure.superclass.constructor.call(this);
    };
    COM.util.defineClass(ADF.figure.DiagramFigure, AGEF.AbrazosUnlimitedFreeformFigure, {
        layout : function(){
            if(this.layoutManager){
                var children = this.getChildren(),
                    that = this;
                children.forEach(function(child, index, array){
                    that.getWidget().layoutChild(child.getWidget());
                    var widgetBounds = child.getWidget().getBounds();
                    var newConstraint = new COM.draw2d.Rectangle(widgetBounds.x, widgetBounds.y, widgetBounds.width, widgetBounds.height);
                    that.getLayoutManager().setConstraint(child, newConstraint);
                });
                this.layoutManager.layout(this);
            }
        }
    });
})();ADF.editpart.DiagramEditPart = function(){
  ADF.editpart.DiagramEditPart.superclass.constructor.call(this);
}

COM.util.defineClass(ADF.editpart.DiagramEditPart, AGEF.AbrazosUnlimitedFreeformEditPart,{
    activate: function(){
        ADF.editpart.DiagramEditPart.superclass.activate.call(this);
        this.getModel().addPropertyChangeListener(this);
    },

    deactivate: function(){
        ADF.editpart.DiagramEditPart.superclass.deactivate.call(this);
        this.getModel().removePropertyChangeListener(this);
    },

    createFigure: function(){
        var diagramFigure = new ADF.figure.DiagramFigure();
        return diagramFigure;
    },

    createEditPolicies: function(){
        ADF.editpart.DiagramEditPart.superclass.createEditPolicies.call(this);
        this.installEditPolicy(COM.gef.EditPolicy.CONTAINER_ROLE, new ADF.policy.DiagramContainerEditPolicy());
        this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.DiagramXYLayoutPolicy());
        this.installEditPolicy(COM.gef.EditPolicy.SELECTION_FEEDBACK_ROLE, new ADF.policy.SnapPolicy());
        this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new AGEF.ComponentEditPolicy());
    },

    getModelChildren: function(){
        var diagram = this.getModel();
        return diagram.getChildren();
    },

    propertyChange: function (evt) {
        var prop = evt.getPropertyName();
        if('children' == prop){
          this.refreshChildren();
        }
    }
});
/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.Diagram = function(){
    ADF.control.Diagram.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Diagram, ADF.ControlDescriptor,{

    getEditpart : function(){
        return ADF.editpart.DiagramEditPart;
    },

    getModel : function(){
        return ADF.model.DiagramModel;
    }

});ADF.domControl.Image = function(parent) {
    ADF.domControl.Image.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Image, ADF.domControl.BaseControl, {
    getLabel: function() {
        return "Image";
    },
    setSrc: function(src) {
        $(this.domElement).attr("src", src);
    },
    _getDomElement: function(model) {
        var Image = COM.util.HTMLUtil.createELement('<img src="' + model.getSrc() + '"/>');
        return Image[0];
    }

});ADF.policy.ImageComponentEditPartPolicy = function() {
    ADF.policy.ImageComponentEditPartPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.ImageComponentEditPartPolicy, AGEF.ComponentEditPolicy, {

});ADF.model.ImageModel = function() {
    ADF.model.ImageModel.superclass.constructor.call(this);
};

ADF.model.ImageModel.PROPERTY_SRC = "src";

COM.util.defineClass(ADF.model.ImageModel, ADF.model.BaseModel, {

    initModel: function() {
        ADF.model.ImageModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.ImageModel.PROPERTY_SRC, "", "", true, "图片路径"));
    },
    setSrc: function(src) {
        this.setPropertyValue(ADF.model.ImageModel.PROPERTY_SRC, src);
    },
    getSrc: function() {
        return this.getPropertyValue(ADF.model.ImageModel.PROPERTY_SRC);
    },

    _getModelType: function() {
        return "ADF.model.ImageModel";
    },

    _getName : function(){
        return 'image';  
    },

    fillSerializedJson: function(jsonObject) {
        jsonObject[ADF.model.ImageModel.PROPERTY_SRC] = this.getPropertyDescriptor(ADF.model.ImageModel.PROPERTY_SRC).serialize();
    },

    _deserialize: function(jsonObject) {
        var newProp = null;

        newProp = new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.ImageModel.PROPERTY_SRC]);
        this.propertyDescriptors.put(newProp.getName(), newProp);
    }
});ADF.control.Image = function() {
    ADF.control.Image.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Image, ADF.ControlDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var ImageFigure = new AGEF.WidgetFigure(this.id);
                var Image = this.getWidgetFactory().createControl(this.getModel());
                ImageFigure.setWidget(Image);
                return ImageFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new ADF.policy.ImageComponentEditPartPolicy());
            // },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
                    if (ADF.model.ImageModel.PROPERTY_SRC == evt.getPropertyName()) {
                        this.getFigure().getWidget().setSrc(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.ImageModel;
    },

    getDomControl: function() {
        return ADF.domControl.Image;
    }

});/**
 * @author zhengjiachao
 * @since 2017-4-6
 */
ADF.domControl.Input = function(parent) {
    ADF.domControl.Input.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Input, ADF.domControl.BaseControl, {
    getLabel: function(){
        return "Input";
    },
    setText: function(text) {
        this.domElement.value = text;
    },
    setInputtype:function(type){
        this.domElement.setAttribute('type',type);
    },
    _getDomElement: function(model) {
        var dom = COM.util.HTMLUtil.createELement('<input type="text" style="overflow:hidden;" value="'+model.getText()+'"/>');
        return dom[0];
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.model.InputModel = function(){
    ADF.model.InputModel.superclass.constructor.call(this);
};

ADF.model.InputModel.PROPERTY_TEXT = "text";
ADF.model.InputModel.PROPERTY_INPUTTYPE = "type";

COM.util.defineClass(ADF.model.InputModel, ADF.model.BaseModel,{

    initModel: function() {
        ADF.model.InputModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.InputModel.PROPERTY_TEXT, "", "", true, "文本"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.InputModel.PROPERTY_INPUTTYPE, "", "", true, "文本样式"));
    },
    setText: function(text) {
        this.setPropertyValue(ADF.model.InputModel.PROPERTY_TEXT, text);
    },
    getText: function() {
        return this.getPropertyValue(ADF.model.InputModel.PROPERTY_TEXT);
    },
    setInputtype: function(type) {
        this.setPropertyValue(ADF.model.InputModel.PROPERTY_INPUTTYPE, type);
    },
    getInputtype: function() {
        return this.getPropertyValue(ADF.model.InputModel.PROPERTY_INPUTTYPE);
    },

    _getModelType : function(){
        return "ADF.model.InputModel";
    },

    _getName : function(){
        return 'input';  
    },

    fillSerializedJson : function(jsonObject){
        jsonObject[ADF.model.InputModel.PROPERTY_TEXT]=this.getPropertyDescriptor(ADF.model.InputModel.PROPERTY_TEXT).serialize();
        jsonObject[ADF.model.InputModel.PROPERTY_INPUTTYPE]=this.getPropertyDescriptor(ADF.model.InputModel.PROPERTY_INPUTTYPE).serialize();
    },

    _deserialize:function (jsonObject) {
        var newProp=null;

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.InputModel.PROPERTY_TEXT]);
        this.propertyDescriptors.put(newProp.getName(),newProp);

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.InputModel.PROPERTY_INPUTTYPE]);
        this.propertyDescriptors.put(newProp.getName(),newProp);
    }
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.Input = function() {
    ADF.control.Input.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Input, ADF.ControlDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var InputFigure = new AGEF.WidgetFigure(this.id);
                var Input = this.getWidgetFactory().createControl(this.getModel());
                InputFigure.setWidget(Input);
                return InputFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new AGEF.ComponentEditPolicy());
            // },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
                    if (ADF.model.InputModel.PROPERTY_TEXT == evt.getPropertyName()) {
                        this.getFigure().getWidget().setText(evt.newValue);
                    } else if (ADF.model.InputModel.PROPERTY_INPUTTYPE == evt.getPropertyName()) {
                        this.getFigure().getWidget().setInputtype(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.InputModel;
    },

    getDomControl : function(){
        return ADF.domControl.Input;
    }

});/**
 * Created by zhangwenlei on 2017/4/11.
 */
ADF.domControl.Label = function(parent) {
    ADF.domControl.Label.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Label, ADF.domControl.BaseControl, {
    getLabel: function(){
        return "Label";
    },
    setText: function(text) {
        $(this.domElement).find("label").html(text);
    },
    _getDomElement: function(model) {
        var label = COM.util.HTMLUtil.createELement('<div class="text-center"><div style="display:table;width:100%;height:100%;"><label style="display:table-cell;vertical-align:middle;">'+model.getText()+'</label></div></div>');
        return label[0];
    }

});/**
 * Created by zhangwenlei on 2017/4/11.
 */
ADF.policy.LabelComponentEditPartPolicy=function(){
    ADF.policy.LabelComponentEditPartPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.LabelComponentEditPartPolicy,AGEF.ComponentEditPolicy,{

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.model.LabelModel = function(){
    ADF.model.LabelModel.superclass.constructor.call(this);
};

ADF.model.LabelModel.PROPERTY_TEXT="text";

COM.util.defineClass(ADF.model.LabelModel, ADF.model.BaseModel,{

    initModel:function () {
        ADF.model.LabelModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.LabelModel.PROPERTY_TEXT, "", "", true, "文本"));
    },
    setText:function(text){
        this.setPropertyValue(ADF.model.LabelModel.PROPERTY_TEXT, text);
    },
    getText:function(){
        return this.getPropertyValue(ADF.model.LabelModel.PROPERTY_TEXT);
    },
    _getModelType : function(){
        return "ADF.model.LabelModel";
    },

    _getName : function(){
        return 'label';  
    },

    fillSerializedJson : function(jsonObject){
        jsonObject[ADF.model.LabelModel.PROPERTY_TEXT]=this.getPropertyDescriptor(ADF.model.LabelModel.PROPERTY_TEXT).serialize();
    },

    _deserialize:function (jsonObject) {
        var newProp=null;

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.LabelModel.PROPERTY_TEXT]);
        this.propertyDescriptors.put(newProp.getName(),newProp);
    }
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.control.Label = function(){
    ADF.control.Label.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Label, ADF.ControlDescriptor,{

    getEditpart : function(){
        var editpart = function(){
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure:function(){
                var labelFigure=new AGEF.WidgetFigure(this.id);
                var label=this.getWidgetFactory().createControl(this.getModel());
                labelFigure.setWidget(label);
                return labelFigure;
            },
            // createEditPolicies:function(){
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE,new ADF.policy.LabelComponentEditPartPolicy());
            // },
            propertyChange:function(evt){
                editpart.superclass.propertyChange.call(this, evt);
                if(AGEF.PropertyChangeEvent.UPDATE_EVENT==evt.getType()){
                    if(ADF.model.LabelModel.PROPERTY_TEXT==evt.getPropertyName()){
                        this.getFigure().getWidget().setText(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel : function(){
        return ADF.model.LabelModel;
    },

    getDomControl:function(){
        return ADF.domControl.Label;
    }

});/**
 * Created by zhangwenlei on 2017/5/1.
 */
ADF.domControl.Number = function(parent) {
    ADF.domControl.Number.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.Number, ADF.domControl.BaseControl, {
    getLabel: function () {
        return "Number";
    },
    setADFPrecision: function (precision) {
        if (precision) {
            $(this.domElement).attr("ADFPrecision", precision);
        } else {
            $(this.domElement).removeAttr("ADFPrecision");
        }
    },
    setADFIcon: function (icon) {
        if (icon) {
            $(this.domElement.lastChild).addClass("input-group-addon").text(icon);
        } else {
            $('.input-group-addon').text("").removeClass("input-group-addon");
        }
    },
    setQuartile: function(quartile){
        if(quartile == "true"){
            $(this.domElement).attr("quartile",quartile);
        }else if(quartile == "false"){
            $(this.domElement).removeAttr("quartile");
        }
    },
    _getDomElement: function (model) {
        var number = COM.util.HTMLUtil.createELement('<div class="input-group"><input class="form-control" style="height: 100%"/><span></span></div>');
        number.find('input').css('padding','0');
        return number[0];
    }
});/**
 * Created by zhangwenlei on 2017/5/1.
 */
ADF.model.NumberModel = function(){
    ADF.model.NumberModel.superclass.constructor.call(this);
};

ADF.model.NumberModel.PROPERTY_ADFPRECISION = "precision";
ADF.model.NumberModel.PROPERTY_ADFICON = "icon";
ADF.model.NumberModel.PROPERTY_QUARTILE = "quartile";

COM.util.defineClass(ADF.model.NumberModel, ADF.model.BaseModel,{

    initModel: function() {
        ADF.model.NumberModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.NumberModel.PROPERTY_ADFPRECISION, "", "", true, "精度"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.NumberModel.PROPERTY_ADFICON, "", "", true, "符号图标"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.NumberModel.PROPERTY_QUARTILE, "", "", true, "千分位"));
    },
    setADFPrecision: function(precision) {
        this.setPropertyValue(ADF.model.NumberModel.PROPERTY_ADFPRECISION, precision);
    },
    getADFPrecision: function() {
        return this.getPropertyValue(ADF.model.NumberModel.PROPERTY_ADFPRECISION);
    },
    getADFIcon: function() {
        return this.getPropertyValue(ADF.model.NumberModel.PROPERTY_ADFICON);
    },
    setADFIcon: function(icon) {
        this.setPropertyValue(ADF.model.NumberModel.PROPERTY_ADFICON, icon);
    },
    setQuartile:function(quartile){
        this.setPropertyValue(ADF.model.NumberModel.PROPERTY_QUARTILE, quartile);
    },
    getQuartile:function(){
        return this.getPropertyValue(ADF.model.NumberModel.PROPERTY_QUARTILE);
    },
    _getModelType : function(){
        return "ADF.model.NumberModel";
    },
    _getName : function(){
        return 'number';  
    },

    fillSerializedJson : function(jsonObject){
        jsonObject[ADF.model.NumberModel.PROPERTY_ADFPRECISION]=this.getPropertyDescriptor(ADF.model.NumberModel.PROPERTY_ADFPRECISION).serialize();
        jsonObject[ADF.model.NumberModel.PROPERTY_ADFICON]=this.getPropertyDescriptor(ADF.model.NumberModel.PROPERTY_ADFICON).serialize();
        jsonObject[ADF.model.NumberModel.PROPERTY_QUARTILE]=this.getPropertyDescriptor(ADF.model.NumberModel.PROPERTY_QUARTILE).serialize();
    },

    _deserialize:function (jsonObject) {
        var newProp=null;
        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.NumberModel.PROPERTY_ADFPRECISION]);
        this.propertyDescriptors.put(newProp.getName(),newProp);

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.NumberModel.PROPERTY_ADFICON]);
        this.propertyDescriptors.put(newProp.getName(),newProp);

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.NumberModel.PROPERTY_QUARTILE]);
        this.propertyDescriptors.put(newProp.getName(),newProp);
    }
});/**
 * Created by zhangwenlei on 2017/5/1.
 */
ADF.control.Number = function() {
    ADF.control.Number.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.Number,ADF.ControlDescriptor,{

    getEditpart:function () {
        var editpart=function () {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart,ADF.editpart.BaseEditpart,{
            _createFigure: function() {
                var NumberFigure = new AGEF.WidgetFigure(this.id);
                var Number = this.getWidgetFactory().createControl(this.getModel());
                NumberFigure.setWidget(Number);
                return NumberFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new AGEF.ComponentEditPolicy());
            // },
            propertyChange:function(evt){
                editpart.superclass.propertyChange.call(this,evt);
                if(AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()){
                   if(ADF.model.NumberModel.PROPERTY_ADFPRECISION==evt.getPropertyName()){
                       this.getFigure().getWidget().setADFPrecision(evt.newValue);
                   }else if(ADF.model.NumberModel.PROPERTY_ADFICON==evt.getPropertyName()){
                       this.getFigure().getWidget().setADFIcon(evt.newValue);
                   }else if(ADF.model.NumberModel.PROPERTY_QUARTILE==evt.getPropertyName()){
                       this.getFigure().getWidget().setQuartile(evt.newValue);
                   }
               }
            }
        });
        return editpart;
    },

    getModel : function(){
        return ADF.model.NumberModel;
    },

    getDomControl:function(){
        return ADF.domControl.Number;
    }

});/**
 * Created by zhangwenlei on 2017/4/12.
 */
ADF.domControl.TextArea = function(parent) {
    ADF.domControl.TextArea.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.TextArea, ADF.domControl.BaseControl, {
    getLabel: function(){
        return "TextArea";
    },
    setText: function(text) {
        this.domElement.innerHTML = text;
    },
    _getDomElement: function(model) {
        var textarea = COM.util.HTMLUtil.createELement('<textarea class="form-control" rows="5">'+model.getText()+'</textarea>');
        return textarea[0];
    }

});/**
 * Created by zhangwenlei on 2017/4/12.
 */
ADF.policy.TextAreaComponentEditPartPolicy = function(){
    ADF.policy.TextAreaComponentEditPartPolicy.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.policy.TextAreaComponentEditPartPolicy, AGEF.ComponentEditPolicy, {

});/**
 * Created by zhangwenlei on 2017/4/12.
 */
ADF.model.TextAreaModel = function(){
    ADF.model.TextAreaModel.superclass.constructor.call(this);
};

ADF.model.TextAreaModel.PROPERTY_TEXT = "text";

COM.util.defineClass(ADF.model.TextAreaModel, ADF.model.BaseModel,{

    initModel: function() {
        ADF.model.TextAreaModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.TextAreaModel.PROPERTY_TEXT, "", "", true, "文本"));
    },
    setText: function(text) {
        this.setPropertyValue(ADF.model.TextAreaModel.PROPERTY_TEXT, text);
    },
    getText: function() {
        return this.getPropertyValue(ADF.model.TextAreaModel.PROPERTY_TEXT);
    },

    _getModelType : function(){
        return "ADF.model.TextAreaModel";
    },
    _getName : function(){
        return 'textarea';  
    },

    fillSerializedJson : function(jsonObject){
        jsonObject[ADF.model.TextAreaModel.PROPERTY_TEXT]=this.getPropertyDescriptor(ADF.model.TextAreaModel.PROPERTY_TEXT).serialize();
    },

    _deserialize:function (jsonObject) {
        var newProp=null;

        newProp=new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject[ADF.model.TextAreaModel.PROPERTY_TEXT]);
        this.propertyDescriptors.put(newProp.getName(),newProp);
    }
});/**
 * Created by zhangwenlei on 2017/4/11.
 */
ADF.control.TextArea = function() {
    ADF.control.TextArea.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.control.TextArea, ADF.ControlDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var textareaFigure = new AGEF.WidgetFigure(this.id);
                var textarea = this.getWidgetFactory().createControl(this.getModel());
                textareaFigure.setWidget(textarea);
                return textareaFigure;
            },
            // createEditPolicies: function() {
            //     this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new ADF.policy.TextAreaComponentEditPartPolicy());
            // },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
                    if (ADF.model.TextAreaModel.PROPERTY_TEXT == evt.getPropertyName()) {
                        this.getFigure().getWidget().setText(evt.newValue);
                    }
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.TextAreaModel;
    },

    getDomControl : function(){
        return ADF.domControl.TextArea;
    }

});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.property.BaseGroup = function(config){
    this.config = config;
    ADF.property.BaseGroup.superclass.constructor.call(this);
};

ADF.property.BaseGroup.ID = 'baseProperty';

COM.util.defineClass(ADF.property.BaseGroup, ADF.PropertyDescriptor,{

    /**
     * 返回分组定义的一个实例对象，机制会根据分组的实例对象，展示工具界面，并把相应的工具放到分组里
     * 返回值的格式是 {id, instance}
     * id是分组的id，其他工具根据id放入分组， instance是分组对象的一个实例
     */
    getGroupInstance : function(){
        var group = new AGEF.PropertyGroupModel();
        group.setConfig(this.config);
        group.setID(this._getGroupid());
        return group;
    },

    _getGroupid : function(){
        return ADF.property.BaseGroup.ID;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.XYLayoutdataPropertyEditorControl = function(propDescriptor) {
    ADF.property.XYLayoutdataPropertyEditorControl.superclass.constructor.call(this, propDescriptor);
};
ADF.property.XYLayoutdataPropertyEditorControl.LABEL = "XYLayoutDataEditor";
ADF.property.XYLayoutdataPropertyEditorControl.getID = function(){
    return ADF.property.XYLayoutdataPropertyEditorControl.LABEL;
};
COM.util.defineClass(ADF.property.XYLayoutdataPropertyEditorControl, ADF.PropertyEditorControl, {
    createControl: function(propDescriptor) {
        var controlString =  '\
            <div class="form-horizontal" style="margin-bottom:5px;">\
                <div class="form-group" style="position: relative;margin-bottom:5px;">\
                    <div class="col-sm-3" style="margin-left: 2px;padding-top:7px;">\
                        <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="leftTop" class="control-label" title="position">位置</label>\
                    </div>\
                    <div class="col-sm-9 form-group" style="margin-left: -25px;">\
                        <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                           <input type="text" class="form-control" part="left" style="text-align:center;">\
                           <label style="padding-top:3px;">X</label>\
                        </div>\
                        <div class="col-sm-2" style="text-align:center;padding-left:0;padding-right:0;"><i class="iconfont icon-cheng" style="font-size:20px;position:relative;top:8px;"></i></div>\
                        <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                           <input type="text" class="form-control" part="top" style="text-align:center;">\
                           <label style="padding-top:3px;">Y</label>\
                        </div>\
                    </div>\
                </div>\
                <div class="form-group" style="position: relative;">\
                    <div class="col-sm-3" style="margin-left: 2px;padding-top:7px;">\
                        <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="widthHeight" class="control-label" title="size">大小</label>\
                    </div>\
                    <div class="col-sm-9 form-group" style="margin-left: -25px;">\
                       <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                          <input type="text" class="form-control" part="width" style="text-align:center;">\
                          <label style="padding-top:3px;">宽</label>\
                       </div>\
                       <div class="col-sm-2" style="text-align:center;padding-left:0;padding-right:0;"><i class="iconfont icon-weisuoding" style="font-size:20px;position:relative;top:8px;"></i></div>\
                       <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                          <input type="text" class="form-control" part="height" style="text-align:center;">\
                          <label style="padding-top:3px;">高</label>\
                       </div>\
                    </div>\
                </div>\
            </div>\
            ';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        this.setValue(propDescriptor.getValue());
    },
    getControl: function() {
        return this.control;
    },
    setValue: function(value) {
        COM.util.HTMLUtil.getChildren(this.control, "input[part=left]").val(value.x);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=top]").val(value.y);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=width]").val(value.width);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=height]").val(value.height);
    },
    getValue: function() {
        return new COM.draw2d.Rectangle(
            COM.util.HTMLUtil.getChildren(this.control, "input[part=left]").val(),
            COM.util.HTMLUtil.getChildren(this.control, "input[part=top]").val(),
            COM.util.HTMLUtil.getChildren(this.control, "input[part=width]").val(),
            COM.util.HTMLUtil.getChildren(this.control, "input[part=height]").val()
        );
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, "input").bind('input propertychange', function() {
            var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(this.propDescriptor.getName());
            request.setValue(this.getValue());
            handler(request);
        }.bind(this));
    },
    getID : function(){
        return ADF.property.XYLayoutdataPropertyEditorControl.LABEL;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.ButtonGroupLayoutDataEditorControl = function(propDescriptor) {
    ADF.property.ButtonGroupLayoutDataEditorControl.superclass.constructor.call(this, propDescriptor);
};
ADF.property.ButtonGroupLayoutDataEditorControl.LABEL = "ButtonGroupLayoutDataEditor";
ADF.property.ButtonGroupLayoutDataEditorControl.getID = function(){
    return ADF.property.ButtonGroupLayoutDataEditorControl.LABEL;
};
COM.util.defineClass(ADF.property.ButtonGroupLayoutDataEditorControl, ADF.PropertyEditorControl, {
    createControl: function(propDescriptor) {
        var controlString =  '\
            <div class="form-horizontal">\
                <div class="form-group" style="position: relative;">\
                    <div class="col-sm-3" style="text-align: center;margin-left: 2px">\
                        <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="width" class="control-label" title="width">width</label>\
                    </div>\
                    <div class="col-sm-9" style="margin-left: -25px">\
                        <input type="text" class="form-control" part="width">\
                    </div>\
                </div>\
                <div class="form-group" style="position: relative;">\
                    <div class="col-sm-3" style="text-align: center;margin-left: 2px">\
                        <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="height">height</label>\
                    </div>\
                    <div class="col-sm-9" style="margin-left: -25px">\
                        <input type="text" class="form-control" part="height">\
                    </div>\
                </div>\
            </div>\
            ';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        this.setValue(propDescriptor.getValue());
    },
    getControl: function() {
        return this.control;
    },
    setValue: function(value) {
        COM.util.HTMLUtil.getChildren(this.control, "input[part=width]").val(value.x);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=height]").val(value.y);
    },
    getValue: function() {
        return new COM.draw2d.Point(
            COM.util.HTMLUtil.getChildren(this.control, "input[part=width]").val(),
            COM.util.HTMLUtil.getChildren(this.control, "input[part=height]").val()
        );
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, "input").bind('input propertychange', function() {
            var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(this.propDescriptor.getName());
            request.setValue(this.getValue());
            handler(request);
        }.bind(this));
    },
    getID : function(){
        return ADF.property.ButtonGroupLayoutDataEditorControl.LABEL;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.ContainerLayoutDataEditorControl = function(propDescriptor) {
    ADF.property.ContainerLayoutDataEditorControl.superclass.constructor.call(this, propDescriptor);
};
ADF.property.ContainerLayoutDataEditorControl.LABEL = "ContainerLayoutDataEditor";
ADF.property.ContainerLayoutDataEditorControl.getID = function(){
    return ADF.property.ContainerLayoutDataEditorControl.LABEL;
};
COM.util.defineClass(ADF.property.ContainerLayoutDataEditorControl, ADF.PropertyEditorControl, {
    createControl: function(propDescriptor) {
        var controlString =  '<div class="form-horizontal" style="margin-bottom:5px;"><div class="form-group" style="position: relative;">' +
            '<div class="col-sm-3" style="margin-left: 2px"><label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="height">height</label></div>' +
            '<div class="col-sm-9" style="margin-left: -25px">' +
            '<input type="text" class="form-control" id="height" value="'+propDescriptor.getValue()+ '">' +
            '</div></div></div>';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        this.setValue(propDescriptor.getValue());
    },
    getControl: function() {
        return this.control;
    },
    setValue: function(value) {
        COM.util.HTMLUtil.getChildren(this.control, "input").val(value);
    },
    getValue: function() {
        return COM.util.HTMLUtil.getChildren(this.control, "input").val();
        
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, "input").bind('input propertychange', function() {
            var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(this.propDescriptor.getName());
            request.setValue(this.getValue());
            handler(request);
        }.bind(this));
    },
    getID : function(){
        return ADF.property.ContainerLayoutDataEditorControl.LABEL;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.RowLayoutDataEditorControl = function(propDescriptor) {
    ADF.property.RowLayoutDataEditorControl.superclass.constructor.call(this, propDescriptor);
};
ADF.property.RowLayoutDataEditorControl.LABEL = "RowLayoutDataEditor";
ADF.property.RowLayoutDataEditorControl.getID = function(){
    return ADF.property.RowLayoutDataEditorControl.LABEL;
};
COM.util.defineClass(ADF.property.RowLayoutDataEditorControl, ADF.PropertyEditorControl, {
    createControl: function(propDescriptor) {
        var controlString =  '\
        <div class="form-horizontal" style="margin-bottom:5px;">\
           <div class="form-group" style="position: relative;margin-bottom:5px">\
               <div class="col-sm-3" style="margin-left: 2px;padding-top:7px;">\
                   <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="height">Height</label>\
               </div>\
               <div class="col-sm-9" style="margin-left: -25px">\
                   <input type="text" class="form-control" id="height" part="bpheight">\
               </div>\
            </div>\
            <div class="form-group" style="position: relative;margin-bottom:5px">\
               <div class="col-sm-3" style="margin-left: 2px;padding-top:7px;">\
                   <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="列宽">列宽</label>\
               </div>\
               <div class="col-sm-9 form-group" style="margin-left: -25px">\
                   <div class="col-sm-3 dropdown" style="padding-left:0;padding-right:0;text-align:center;">\
                      <div class="form-control dropdown-toggle" id="bpxs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="padding:0;text-align:left;">\
                          <input type="text" part="bpxs" style="text-align:center;width:55%;height:100%;border:none;outline:none;">\
                          <i class="iconfont icon-down"></i>\
                      </div>\
                      <label style="padding-top:3px">xs</label>\
                      <ul _name="xs" class="dropdown-menu bpxs" style="top:32px;" aria-labelledby="bpxs"></ul>\
                   </div>\
                   <div class="col-sm-3 dropdown" style="padding-left:0;padding-right:0;text-align:center;">\
                      <div class="form-control dropdown-toggle" id="bpsm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="padding:0;text-align:left;">\
                          <input type="text" part="bpsm" style="text-align:center;width:55%;height:100%;border:none;outline:none;">\
                          <i class="iconfont icon-down"></i>\
                      </div>\
                      <label style="padding-top:3px">sm</label>\
                      <ul _name="sm" class="dropdown-menu bpsm" style="top:32px;" aria-labelledby="bpsm"></ul>\
                   </div>\
                   <div class="col-sm-3 dropdown" style="padding-left:0;padding-right:0;text-align:center;">\
                      <div class="form-control dropdown-toggle" id="bpmd" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="padding:0;text-align:left;">\
                          <input type="text" part="bpmd" style="text-align:center;width:55%;height:100%;border:none;outline:none;">\
                          <i class="iconfont icon-down"></i>\
                      </div>\
                      <label style="padding-top:3px">md</label>\
                      <ul _name="md" class="dropdown-menu bpmd" style="top:32px;left:auto;right:0;" aria-labelledby="bpmd"></ul>\
                   </div>\
                   <div class="col-sm-3 dropdown" style="padding-left:0;padding-right:0;text-align:center;">\
                      <div class="form-control dropdown-toggle" id="bplg" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="padding:0;text-align:left;">\
                          <input type="text" part="bplg" style="text-align:center;width:55%;height:100%;border:none;outline:none;">\
                          <i class="iconfont icon-down"></i>\
                      </div>\
                      <label style="padding-top:3px">lg</label>\
                      <ul _name="lg" class="dropdown-menu bplg" style="top:32px;left:auto;right:0;" aria-labelledby="bplg"></ul>\
                   </div>\
               </div>\
            </div>\
        </div>';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        this.setValue(propDescriptor.getValue());
        var $bpxs = COM.util.HTMLUtil.getChildren(this.control,".bpxs");
        for(var i=1;i<13;i++){
            $bpxs.append('<li style="display:inline-block;text-align:center;width:25%;height:30px;line-height:30px;">'+i+'</li>');
        };
        var $bpsm = COM.util.HTMLUtil.getChildren(this.control,".bpsm");
        for(var i=1;i<13;i++){
            $bpsm.append('<li style="display:inline-block;text-align:center;width:25%;height:30px;line-height:30px;">'+i+'</li>');
        };
        var $bpmd = COM.util.HTMLUtil.getChildren(this.control,".bpmd");
        for(var i=1;i<13;i++){
            $bpmd.append('<li style="display:inline-block;text-align:center;width:25%;height:30px;line-height:30px;">'+i+'</li>');
        };
        var $bplg = COM.util.HTMLUtil.getChildren(this.control,".bplg");
        for(var i=1;i<13;i++){
            $bplg.append('<li style="display:inline-block;text-align:center;width:25%;height:30px;line-height:30px;">'+i+'</li>');
        };

    },
    getControl: function() {
        return this.control;
    },
    setValue: function(value) {
        COM.util.HTMLUtil.getChildren(this.control, "input[part=bpxs]").val(value.xs);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=bpsm]").val(value.sm);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=bpmd]").val(value.md);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=bplg]").val(value.lg);
        COM.util.HTMLUtil.getChildren(this.control, "input[part=bpheight]").val(value.height);
    },
    getValue: function() {
        var colData = new ADF.layoutData.ColData();
        colData.setXs(COM.util.HTMLUtil.getChildren(this.control, "input[part=bpxs]").val());
        colData.setSm(COM.util.HTMLUtil.getChildren(this.control, "input[part=bpsm]").val());
        colData.setMd(COM.util.HTMLUtil.getChildren(this.control, "input[part=bpmd]").val());
        colData.setLg(COM.util.HTMLUtil.getChildren(this.control, "input[part=bplg]").val());
        colData.setHeight(COM.util.HTMLUtil.getChildren(this.control, "input[part=bpheight]").val()); 
        return colData;
    },
    bindChangeFunction:function(obj,handler){
        var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(obj.propDescriptor.getName());
            request.setValue(obj.getValue());
            handler(request);
        return request;
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, "input").bind('input propertychange', function() {
            this.bindChangeFunction(this,handler);
        }.bind(this));
        COM.util.HTMLUtil.getChildren(this.control,".dropdown-menu li").bind('click',function(e){
            var bpName = $(e.target).parent().attr('_name'),
                bpText = $(e.target).text();
            if(bpName == 'xs'){
                COM.util.HTMLUtil.getChildren(this.control, "input[part=bpxs]").val(bpText);
            }else if(bpName == 'sm'){
                COM.util.HTMLUtil.getChildren(this.control, "input[part=bpsm]").val(bpText);
            }else if(bpName == 'md'){
                COM.util.HTMLUtil.getChildren(this.control, "input[part=bpmd]").val(bpText);
            }else if(bpName == 'lg'){
                COM.util.HTMLUtil.getChildren(this.control, "input[part=bplg]").val(bpText);
            }
            this.bindChangeFunction(this,handler);
        }.bind(this));
    },
    getID : function(){
        return ADF.property.RowLayoutDataEditorControl.LABEL;
    }
});ADF.property.DiagramLayoutDataEditorControl = function(propDescriptor) {
    ADF.property.DiagramLayoutDataEditorControl.superclass.constructor.call(this, propDescriptor);
};
ADF.property.DiagramLayoutDataEditorControl.LABEL = "DiagramLayoutDataEditor";
ADF.property.DiagramLayoutDataEditorControl.getID = function(){
    return ADF.property.DiagramLayoutDataEditorControl.LABEL;
};
COM.util.defineClass(ADF.property.DiagramLayoutDataEditorControl,ADF.PropertyEditorControl,{
    createControl:function(propDescriptor){
        var controlString = '\
        <div class="form-horizontal" style="margin-bottom:5px;">\
            <div class="form-group" style="position: relative;margin-bottom:8px">\
               <div class="col-sm-3" style="margin-left: 2px;">\
                   <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="autoSize">自适应</label>\
               </div>\
               <div class="col-sm-9 checkbox" style="margin-left: -25px">\
                   <label><input type="checkbox" part="dmAutoSize"></label>\
                </div>\
            </div>\
            <div class="form-group" style="position: relative;margin-bottom:8px">\
               <div class="col-sm-3" style="margin-left: 2px;">\
                  <label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="height" class="control-label" title="宽高">宽高</label>\
               </div>\
               <div class="col-sm-9" style="margin-left: -25px">\
                   <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                      <input type="text" class="form-control" part="dmWidth" style="text-align:center;">\
                      <label style="padding-top:5px;">宽</label>\
                   </div>\
                   <div class="col-sm-2" style="text-align:center;padding-left:0;padding-right:0;"><i class="iconfont icon-cheng" style="font-size:20px;position:relative;top:8px;"></i></div>\
                  <div class="col-sm-5" style="padding-left:0;padding-right:0;text-align:center;">\
                     <input type="text" class="form-control" part="dmHeight" style="text-align:center;">\
                     <label style="padding-top:5px;">高</label>\
                  </div>\
               </div>\
            </div>\
        </div>';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        this.setValue(propDescriptor.getValue());
    },
    getControl:function(){
        return this.control;
    },
    setValue:function(value){
        COM.util.HTMLUtil.getChildren(this.control, "input[part=dmWidth]").val(value.width);
        COM.util.HTMLUtil.getChildren(this.control,"input[part=dmHeight]").val(value.height);
    },
    getValue:function(){
        var diagramData = new ADF.layoutData.DiagramData();
        diagramData.setWidth(COM.util.HTMLUtil.getChildren(this.control, "input[part=dmWidth]").val());
        diagramData.setHeight(COM.util.HTMLUtil.getChildren(this.control, "input[part=dmHeight]").val());
        return diagramData;
    },
    bindChangeFunction:function(obj,handler){
        var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(obj.propDescriptor.getName());
            request.setValue(obj.getValue());
            handler(request);
        return request;
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, "input").bind('input propertychange', function() {
           this.bindChangeFunction(this,handler);
        }.bind(this));
        // COM.util.HTMLUtil.getChildren(this.control,"input[part=dmAutoSize]").bind('click',function(){
        //     var autoSizeValue = COM.util.HTMLUtil.getChildren(this.control, "input[part=dmAutoSize]").prop("checked");
        //     if(autoSizeValue){
        //         COM.util.HTMLUtil.getChildren(this.control, "input[part=dmWidth]").attr("disabled",true);
        //         COM.util.HTMLUtil.getChildren(this.control,"input[part=dmHeight]").attr("disabled",true);
        //     }else{
        //         COM.util.HTMLUtil.getChildren(this.control, "input[part=dmWidth]").attr("disabled",false);
        //         COM.util.HTMLUtil.getChildren(this.control,"input[part=dmHeight]").attr("disabled",false);
        //     }
        //     this.bindChangeFunction(this,handler);
        // }.bind(this));
    },
    getID:function(){
        return ADF.property.DiagramLayoutDataEditorControl.LABEL;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.XYLayoutdataPropertyEditor = function(title){
    this.title = title;
    ADF.property.XYLayoutdataPropertyEditor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.property.XYLayoutdataPropertyEditor, ADF.PropertyDescriptor,{

    getEditorControl : function(){
        return ADF.property.XYLayoutdataPropertyEditorControl;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.ButtonGroupLayoutDataEditor = function(title){
    this.title = title;
    ADF.property.ButtonGroupLayoutDataEditor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.property.ButtonGroupLayoutDataEditor, ADF.PropertyDescriptor,{

    getEditorControl : function(){
        return ADF.property.ButtonGroupLayoutDataEditorControl;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.ContainerLayoutDataEditor = function(title){
    this.title = title;
    ADF.property.ContainerLayoutDataEditor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.property.ContainerLayoutDataEditor, ADF.PropertyDescriptor,{

    getEditorControl : function(){
        return ADF.property.ContainerLayoutDataEditorControl;
    }
});/**
 * Created by zhangwenlei on 2017/5/24.
 */
ADF.property.RowLayoutDataEditor = function(title){
    this.title = title;
    ADF.property.RowLayoutDataEditor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.property.RowLayoutDataEditor, ADF.PropertyDescriptor,{

    getEditorControl : function(){
        return ADF.property.RowLayoutDataEditorControl;
    }
});ADF.property.DiagramLayoutDataEditor = function(title){
    this.title = title;
    ADF.property.DiagramLayoutDataEditor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.property.DiagramLayoutDataEditor, ADF.PropertyDescriptor,{

    getEditorControl : function(){
        return ADF.property.DiagramLayoutDataEditorControl;
    }
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.tool.BaseGroup = function(config){
    this.config= config;
    ADF.tool.BaseGroup.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.tool.BaseGroup, ADF.ToolDescriptor,{

    /**
     * 返回分组定义的一个实例对象，机制会根据分组的实例对象，展示工具界面，并把相应的工具放到分组里
     * 返回值的格式是 {id, instance}
     * id是分组的id，其他工具根据id放入分组， instance是分组对象的一个实例
     */
    getGroupInstance : function(){
        var group = new AGEF.PaletteGroupModel();
        group.setConfig(this.config);
        return {
            id : this._getGroupid(),
            instance : group
        };
    },

    /**
     * 返回一个工具的实例对象，机制会把工具放到对应的分组中
     * 返回值的格式是 {id, instance}
     * id是分组的id，工具根据id放入预先定义好的分组， instance是工具对象的一个实例
     */
    getToolModelInstance : function(){
        return null;
    },

    _getGroupid : Function.needOverride
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.tool.SelectionGroup = function(){
    ADF.tool.SelectionGroup.superclass.constructor.call(this, this._getTitle());
};

ADF.tool.SelectionGroup.Groupid = 'adf.selectiongroup';

COM.util.defineClass(ADF.tool.SelectionGroup, ADF.tool.BaseGroup,{

    _getGroupid : function(){
        return ADF.tool.SelectionGroup.Groupid;
    }, 

    _getTitle : function(){
        return {text:"选择"};
    }

});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.tool.CreationGroup = function(){
    ADF.tool.CreationGroup.superclass.constructor.call(this, this._getTitle());
};

ADF.tool.CreationGroup.Groupid = 'adf.creationgroup';

COM.util.defineClass(ADF.tool.CreationGroup, ADF.tool.BaseGroup,{

    _getGroupid : function(){
        return ADF.tool.CreationGroup.Groupid;
    }, 

    _getTitle : function(){
        return {text:"控件",icon:"icon-arrow"};
    }

});/**
 * @author jiangqifan
 * @since 2017-6-11
 */
ADF.tool.MarqueeSelectionTool = function(type){
    this.type = type || AGEF.AbrazosMarqueeSelectionTool.LABEL;
    this.tool = new AGEF.PaletteToolModel();
    this._initTool();
    ADF.tool.SelectionTool.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.tool.MarqueeSelectionTool, ADF.ToolDescriptor,{

    /**
     * 返回一个工具的实例对象，机制会把工具放到对应的分组中
     * 返回值的格式是 {id, instance}
     * id是分组的id，工具根据id放入预先定义好的分组， instance是工具对象的一个实例
     */
    getToolModelInstance : function(){
        return {
            id : this._getGroupid(),
            instance : this.tool
        };
    },

    _getGroupid : function(){
        return ADF.tool.SelectionGroup.Groupid;
    },

    _initTool : function(){
        this.tool.setToolType(this._getType());
    },

    _getType : function(){
        return this.type;
    }
});
/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.tool.SelectionTool = function(type){
    this.type = type || AGEF.AbrazosSelectionTool.LABEL;
    this.tool = new AGEF.PaletteToolModel();
    this._initTool();
    ADF.tool.SelectionTool.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.tool.SelectionTool, ADF.ToolDescriptor,{

    /**
     * 返回一个工具的实例对象，机制会把工具放到对应的分组中
     * 返回值的格式是 {id, instance}
     * id是分组的id，工具根据id放入预先定义好的分组， instance是工具对象的一个实例
     */
    getToolModelInstance : function(){
        return {
            id : this._getGroupid(),
            instance : this.tool
        };
    },

    _getGroupid : function(){
        return ADF.tool.SelectionGroup.Groupid;
    },

    _initTool : function(){
        this.tool.setToolType(this._getType());
    },

    _getType : function(){
        return this.type;
    }
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.tool.CreationTool = function(model, config, type){
    this.model = model;
    this.config = config;
    this.type = type || AGEF.AbrazosCreationTool.LABEL;
    this.tool = new AGEF.PaletteToolModel();
    this._initTool();
    ADF.tool.CreationTool.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.tool.CreationTool, ADF.ToolDescriptor,{

    /**
     * 返回一个工具的实例对象，机制会把工具放到对应的分组中
     * 返回值的格式是 {id, instance}
     * id是分组的id，工具根据id放入预先定义好的分组， instance是工具对象的一个实例
     */
    getToolModelInstance : function(){
        return {
            id : this._getGroupid(),
            instance : this.tool
        };
    },

    _getGroupid : function(){
        return ADF.tool.CreationGroup.Groupid;
    },

    _initTool : function(){
        this.tool.setToolType(this._getType());
        this.tool.setModel(this._getModel()); //设置创建的模型
        this.tool.setConfig(this._getConfig());
    },

    _getType : function(){
        return this.type;
    },

    _getModel : function(){
        return this.model;
    },

    _getConfig : function(){
        return this.config;
    }
});ADF.tool.ContainerGroup = function(){
    ADF.tool.ContainerGroup.superclass.constructor.call(this, this._getTitle());
};

ADF.tool.ContainerGroup.Groupid = 'adf.containergroup';

COM.util.defineClass(ADF.tool.ContainerGroup, ADF.tool.BaseGroup,{

    _getGroupid : function(){
        return ADF.tool.ContainerGroup.Groupid;
    }, 

    _getTitle : function(){
        return {text:"容器",icon:"icon-arrow"};
    }

});ADF.tool.ContainerTool = function(model, config, type){
    ADF.tool.ContainerTool.superclass.constructor.call(this, model, config, type);
};

COM.util.defineClass(ADF.tool.ContainerTool, ADF.tool.CreationTool,{
    _getGroupid : function() {
        return ADF.tool.ContainerGroup.Groupid;
    }
});/**
 * Created by zhengjiachao on 2017/4/26.
 */
(function() {
    ADF.actionModel.DeleteModel = function() {
        ADF.actionModel.DeleteModel.superclass.constructor.call(this);
        this.config = {text:"删除",icon:"icon-shanchu"};
        this.id = "delete";
        this.hotkeyInfo = {
            type : "keydown",
            key : "Delete"
        }
    };

    COM.util.defineClass(ADF.actionModel.DeleteModel, AGEF.CommandActionModel, {
        getCommands: function(graphicalViewer) {
            var theSelections = graphicalViewer.getSelection();
            if (theSelections.length == 0) {
                return [];
            }
            if (theSelections.length == 1 && COM.util.isInstanceOf(theSelections[0], ADF.editpart.DiagramEditPart)) {
                return [];
            }
            var commands = new COM.gef.CompoundCommand();
            theSelections.forEach((item) => {
                if(COM.util.isInstanceOf(theSelections[0], ADF.editpart.DiagramEditPart)){
                    return;
                }
                var model = item.getModel();
                if (COM.util.isInstanceOf(model, ADF.model.BaseModel)) {
                    var cmd = COM.gef.Command.createCommand({
                        execute: function() {
                            this.index = COM.util.Array.indexOf(this.parent.getChildren(), this.node);
                            this.parent.removeChild(this.node);
                        },
                        undo: function() {
                            this.parent.addChild(this.node, this.index);
                        }
                    });

                    cmd.parent = model.getParent();
                    cmd.node = model;
                    commands.add(cmd);

                }
            });
            return [commands];
        },
        getEnabledState : function(graphicalViewer){
            var theSelections = graphicalViewer.getSelection();
            if (theSelections.length == 0) {
                return false;
            }
            if (theSelections.length == 1 && COM.util.isInstanceOf(theSelections[0], ADF.editpart.DiagramEditPart)) {
                return false;
            }
            return true;
        }
    });
})();/**
 * Created by zhengjiachao on 2017/4/26.
 */
(function() {
    ADF.actionModel.RedoModel = function() {
        ADF.actionModel.RedoModel.superclass.constructor.call(this);
        this.config = {text:"重做",icon:"icon-zhongzuo"};
        this.id = "redo";
        this.hotkeyInfo = {
            type : "keydown",
            ctrlKey : true,
            key : "y"
        }
    };

    COM.util.defineClass(ADF.actionModel.RedoModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            if(stack.canRedo()) stack.redo();
        },
        getEnabledState : function(graphicalViewer){
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            return stack.canRedo();
        }
    });
})();/**
 * Created by zhengjiachao on 2017/4/26.
 */
(function() {
    ADF.actionModel.UndoModel = function() {
        ADF.actionModel.UndoModel.superclass.constructor.call(this);
        this.config = {text:"撤销",icon:"icon-chexiao"};
        this.id = "undo";
        this.hotkeyInfo = {
            type : "keydown",
            ctrlKey : true,
            key : "z"
        }
    };

    COM.util.defineClass(ADF.actionModel.UndoModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            if(stack.canUndo()) stack.undo();
        },
        getEnabledState : function(graphicalViewer){
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            return stack.canUndo();
        }
    });
})();/**
 * Created by jiangqifan on 2017/6/20.
 */
(function() {
    ADF.actionModel.TopModel = function() {
        ADF.actionModel.TopModel.superclass.constructor.call(this);
        this.config = {text:"置顶",icon:"icon-zhiding"};
        this.id = "top";
    };

    COM.util.defineClass(ADF.actionModel.TopModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            var cmd = COM.gef.Command.createCommand({
                child: selections[0].model,
                originIndex: -1,
                execute: function() {
                  var child = this.child;
                  var parent = child.parent;

                  var children = parent.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
                  var index = children.indexOf(child);
                  this.originIndex = index;
                  var newChildren = children.slice(0, children.length);
                  newChildren.splice(index,1);
                  newChildren.push(child);
                  parent.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
                },

                undo: function() {
                  var child = this.child;
                  var parent = child.parent;

                  var children = parent.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
                  var newChildren = children.slice(0, children.length);
                  newChildren.pop();
                  newChildren.splice(this.originIndex,0, child);
                  parent.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
                }
            });
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            stack.execute(cmd);
        },
        getEnabledState : function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            if(!selections){
              return false;
            }
            //Diagram不允许调整顺�?
            if(selections.length == 1 && COM.util.isInstanceOf(selections[0], ADF.editpart.DiagramEditPart)){
              return false;
            }
            //TODO 判断�?下布�??
            return selections.length == 1;
        }
    });
})();
/**
 * Created by jiangqifan on 2017/6/20.
 */
(function() {
    ADF.actionModel.BottomModel = function() {
        ADF.actionModel.BottomModel.superclass.constructor.call(this);
        this.config = {text:"置底",icon:"icon-zhidi"};
        this.id = "bottom";
    };

    COM.util.defineClass(ADF.actionModel.BottomModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            var cmd = COM.gef.Command.createCommand({
                child: selections[0].model,
                originIndex: -1,
                execute: function() {
                  var child = this.child;
                  var parent = child.parent;

                  var children = parent.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
                  var index = children.indexOf(child);
                  this.originIndex = index;
                  var newChildren = children.slice(0, children.length);
                  newChildren.splice(index,1);
                  newChildren.unshift(child);
                  parent.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
                },

                undo: function() {
                  var child = this.child;
                  var parent = child.parent;

                  var children = parent.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
                  var newChildren = children.slice(0, children.length);
                  newChildren.shift();
                  newChildren.splice(this.originIndex,0, child);
                  parent.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
                }
            });
            var domain = graphicalViewer.getEditDomain();
            var stack = domain.getCommandStack();
            stack.execute(cmd);
        },
        getEnabledState : function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            if(!selections){
              return false;
            }
            //Diagram不允许调整顺序
            if(selections.length == 1 && COM.util.isInstanceOf(selections[0], ADF.editpart.DiagramEditPart)){
              return false;
            }
            //TODO 判断一下布局?
            return selections.length == 1;
        }
    });
})();
/**
 * Created by zhengjiachao on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYDirBaseModel = function() {
        ADF.actionModel.XYDirBaseModel.superclass.constructor.call(this);
    };

    COM.util.defineClass(ADF.actionModel.XYDirBaseModel, AGEF.ActionModel, {
        execute: function(graphicalViewer, dir){
            if (graphicalViewer.getSelection()) {
                var commands = new COM.gef.CompoundCommand();
                graphicalViewer.getSelection().forEach(function (selectionItem) {
                    var model = selectionItem.model;
                    if (model && !(model.parent instanceof ADF.model.DiagramModel)) {
                        var bounds = model.getLayoutData(),
                            parentBounds = model.parent.getLayoutData(),
                            //获取model的边框值与model.parent的边框值
                            //cw减model.parent左右边框值，ch减model.parent上下边框值
                            cw = parentBounds.width - bounds.width -2,
                            ch = parentBounds.height - bounds.height -2;
                        if(bounds instanceof COM.draw2d.Rectangle){
                            var cmd = COM.gef.Command.createCommand({
                                execute: function execute() {
                                    if ((this.dir == "left") && (bounds.x >= 1)) {
                                        bounds.x = bounds.x - 1;
                                    } else if ((this.dir == "up") && (bounds.y >= 1)) {
                                        bounds.y = bounds.y - 1;
                                    } else if ((this.dir == "right") && (bounds.x <= cw-1)) {
                                        bounds.x = bounds.x + 1;
                                    } else if ((this.dir == "down") && (bounds.y <= ch-1)) {
                                        bounds.y = bounds.y + 1;
                                    }
                                    
                                    model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height));
                                },
                                //键盘撤销操作条件未改
                                undo: function undo() {
                                    if (this.dir == "left") {
                                        bounds.x = bounds.x + 1;
                                    } else if (this.dir == "up") {
                                        bounds.y = bounds.y + 1;
                                    } else if (this.dir == "right") {
                                        bounds.x = bounds.x - 1;
                                    } else if (this.dir == "down") {
                                        bounds.y = bounds.y - 1;
                                    }

                                    model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height));
                                }
                            });
                            cmd.dir = dir;
                            cmd.model = model;
                            commands.add(cmd);
                        }
                    }
                });
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var enable = true;
            if (graphicalViewer.getSelection()) {
                graphicalViewer.getSelection().forEach(function (selectionItem) {
                    var model = selectionItem.model;
                    if (model) {
                        var bounds = selectionItem.model.getLayoutData();
                        if(!(bounds instanceof COM.draw2d.Rectangle)){
                            enable = false;
                            return;
                        }
                    }
                });
            }
            return enable;
        }
    });
})();
/**
 * Created by zhengjiachao on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYUpActionModel = function() {
        ADF.actionModel.XYUpActionModel.superclass.constructor.call(this);
        this.config = {text:"上移",icon:"icon-shangyi"};
        this.id = "XYUp";
        this.hotkeyInfo = {
            type : "keydown",
            key : "ArrowUp"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYUpActionModel, ADF.actionModel.XYDirBaseModel, {
        execute: function(graphicalViewer){
            ADF.actionModel.XYUpActionModel.superclass.execute.call(this, graphicalViewer, "up");
        }
    });
})();
/**
 * Created by zhengjiachao on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYDownActionModel = function() {
        ADF.actionModel.XYDownActionModel.superclass.constructor.call(this);
        this.config = {text:"下移",icon:"icon-xiayi"};
        this.id = "XYDown";
        this.hotkeyInfo = {
            type : "keydown",
            key : "ArrowDown"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYDownActionModel, ADF.actionModel.XYDirBaseModel, {
        execute: function(graphicalViewer){
            ADF.actionModel.XYDownActionModel.superclass.execute.call(this, graphicalViewer, "down");
        }
    });
})();
/**
 * Created by zhengjiachao on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYLeftActionModel = function() {
        ADF.actionModel.XYLeftActionModel.superclass.constructor.call(this);
        this.config = {text:"左移",icon:"icon-zuoyi"};
        this.id = "XYLeft";
        this.hotkeyInfo = {
            type : "keydown",
            key : "ArrowLeft"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYLeftActionModel, ADF.actionModel.XYDirBaseModel, {
        execute: function(graphicalViewer){
            ADF.actionModel.XYLeftActionModel.superclass.execute.call(this, graphicalViewer, "left");
        }
    });
})();
/**
 * Created by zhengjiachao on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYRightActionModel = function() {
        ADF.actionModel.XYRightActionModel.superclass.constructor.call(this);
        this.config = {text:"右移",icon:"icon-youyi"};
        this.id = "XYRight";
        this.hotkeyInfo = {
            type : "keydown",
            key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYRightActionModel, ADF.actionModel.XYDirBaseModel, {
        execute: function(graphicalViewer){
            ADF.actionModel.XYRightActionModel.superclass.execute.call(this, graphicalViewer, "right");
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignBottomModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"居下对齐",icon:"icon-diduiqi"};
        this.id = "XYAlignBottom";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignBottomModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            var bottomMax = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!bottomMax || (bottomMax && bounds.y + bounds.height > bottomMax)){
                        bottomMax = bounds.y + bounds.height;
                    }
                }
            }

            if(bottomMax){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, bottomMax - bounds.height, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
            
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignCenterModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"水平居中对齐",icon:"icon-youduiqi"};
        this.id = "XYAlignCenter";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignCenterModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();

            var leftMin = null;
            var rightMax = null;
            var centerX = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!leftMin || (leftMin && bounds.x < leftMin)){
                        leftMin = bounds.x;
                    }

                    if(!rightMax || (rightMax && bounds.x + bounds.width > rightMax)){
                        rightMax = bounds.x + bounds.width;
                    }
                }
            }

            if(leftMin && rightMax){
                centerX = leftMin + (rightMax - leftMin) / 2;
            }

            if(centerX){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            
                            model.setLayoutData(new COM.draw2d.Rectangle(centerX - bounds.width / 2, bounds.y, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignLeftModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"居左对齐",icon:"icon-zuoduiqi"};
        this.id = "XYAlignLeft";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignLeftModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            var leftMin = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!leftMin || (leftMin && bounds.x < leftMin)){
                        leftMin = bounds.x;
                    }
                }
            }

            if(leftMin){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(leftMin, bounds.y, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignMiddleModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"垂直居中对齐",icon:"icon-juzhongduiqi"};
        this.id = "XYAlignnMiddle";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignMiddleModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            
            var topMin = null;
            var bottomMax = null;
            var middleY = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!topMin || (topMin && bounds.y < topMin)){
                        topMin = bounds.y;
                    }

                    if(!bottomMax || (bottomMax && bounds.y + bounds.height > bottomMax)){
                        bottomMax = bounds.y + bounds.height;
                    }
                }
            }

            if(topMin && bottomMax){
                middleY = topMin + (bottomMax - topMin) / 2;
            }

            if(middleY){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, middleY - bounds.height / 2, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignRightModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"居右对齐",icon:"icon-youduiqi1"};
        this.id = "XYAlignRight";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignRightModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            var rightMax = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!rightMax || (rightMax && bounds.x + bounds.width > rightMax)){
                        rightMax = bounds.x + bounds.width;
                    }
                }
            }

            if(rightMax){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(rightMax - bounds.width, bounds.y, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/21.
 */
(function() {
    ADF.actionModel.XYAlignTopModel = function() {
        ADF.actionModel.XYAlignBottomModel.superclass.constructor.call(this);
        this.config = {text:"居上对齐",icon:"icon-shangduiqi"};
        this.id = "XYAlignTop";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYAlignTopModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            var topMin = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!topMin || (topMin && bounds.y < topMin)){
                        topMin = bounds.y;
                    }
                }
            }

            if(topMin){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, topMin, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 1){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/22.
 */
(function() {
    ADF.actionModel.XYDistributeEvenlyModel = function() {
        ADF.actionModel.XYDistributeEvenlyModel.superclass.constructor.call(this);
        this.config = {text:"平均分布",icon:"icon-shuipingchuizhifenbu"};
        this.id = "XYDistributeEvenly";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYDistributeEvenlyModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            var leftMin = null;
            var rightMax = null;
            
            var leftMinCenter = null;
            var rightMaxCenter = null;
            var totalCenterWidth = null;

            var topMin = null;
            var bottomMax = null;

            var topMinMiddle = null;
            var bottomMaxMiddle = null;
            var totalMiddleHeight = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!leftMin || (leftMin && bounds.x < leftMin)){
                        leftMin = bounds.x;
                    }

                    if(!rightMax || (rightMax && bounds.x + bounds.width > rightMax)){
                        rightMax = bounds.x + bounds.width;
                    }

                    if(!topMin || (topMin && bounds.y < topMin)){
                        topMin = bounds.y;
                    }

                    if(!bottomMax || (bottomMax && bounds.y + bounds.height > bottomMax)){
                        bottomMax = bounds.y + bounds.height;
                    }
                }
            }

            if(leftMin && rightMax){
                leftMinCenter = leftMin + selection[0].model.getLayoutData().width / 2;
                rightMaxCenter = rightMax - selection[selection.length - 1].model.getLayoutData().width / 2;
                totalCenterWidth = rightMaxCenter - leftMinCenter;
            }

            if(topMin && bottomMax){
                topMinMiddle = topMin + selection[0].model.getLayoutData().height / 2;
                bottomMaxMiddle = bottomMax - selection[selection.length - 1].model.getLayoutData().height / 2;
                totalMiddleHeight = bottomMaxMiddle - topMinMiddle;
            }

            if(leftMinCenter && rightMaxCenter && totalCenterWidth && topMinMiddle && bottomMaxMiddle && totalMiddleHeight){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(leftMinCenter + totalCenterWidth / (selection.length - 2 + 1) * i - bounds.width / 2, topMinMiddle + totalMiddleHeight / (selection.length - 2 + 1) * i - bounds.height / 2, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
            
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 2){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/22.
 */
(function() {
    ADF.actionModel.XYDistributeHorizontallyModel = function() {
        ADF.actionModel.XYDistributeHorizontallyModel.superclass.constructor.call(this);
        this.config = {text:"水平分布",icon:"icon-chuizhifenbu"};
        this.id = "XYDistributeHorizontally";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYDistributeHorizontallyModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();

            var leftMin = null;
            var rightMax = null;
            
            var leftMinCenter = null;
            var rightMaxCenter = null;
            var totalCenterWidth = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!leftMin || (leftMin && bounds.x < leftMin)){
                        leftMin = bounds.x;
                    }

                    if(!rightMax || (rightMax && bounds.x + bounds.width > rightMax)){
                        rightMax = bounds.x + bounds.width;
                    }
                }
            }

            if(leftMin && rightMax){
                leftMinCenter = leftMin + selection[0].model.getLayoutData().width / 2;
                rightMaxCenter = rightMax - selection[selection.length - 1].model.getLayoutData().width / 2;
                totalCenterWidth = rightMaxCenter - leftMinCenter;
            }

            

            if(leftMinCenter && rightMaxCenter && totalCenterWidth){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            
                            model.setLayoutData(new COM.draw2d.Rectangle(leftMinCenter + totalCenterWidth / (selection.length - 2 + 1) * i - bounds.width / 2, bounds.y, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 2){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by king on 2017/6/22.
 */
(function() {
    ADF.actionModel.XYDistributeVerticallyModel = function() {
        ADF.actionModel.XYDistributeVerticallyModel.superclass.constructor.call(this);
        this.config = {text:"垂直分布",icon:"icon-shuipingfenbu"};
        this.id = "XYDistributeVertically";
        this.hotkeyInfo = {
            // type : "keydown",
            // key : "ArrowRight"
        }
    };

    COM.util.defineClass(ADF.actionModel.XYDistributeVerticallyModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            
            var topMin = null;
            var bottomMax = null;

            var topMinMiddle = null;
            var bottomMaxMiddle = null;
            var totalMiddleHeight = null;
            
            for(var i in selection){
                var selectionItem = selection[i];
                var bounds = selectionItem.model.getLayoutData();
                if(bounds instanceof COM.draw2d.Rectangle){
                    if(!topMin || (topMin && bounds.y < topMin)){
                        topMin = bounds.y;
                    }

                    if(!bottomMax || (bottomMax && bounds.y + bounds.height > bottomMax)){
                        bottomMax = bounds.y + bounds.height;
                    }
                }
            }

            if(topMin && bottomMax){
                topMinMiddle = topMin + selection[0].model.getLayoutData().height / 2;
                bottomMaxMiddle = bottomMax - selection[selection.length - 1].model.getLayoutData().height / 2;
                totalMiddleHeight = bottomMaxMiddle - topMinMiddle;
            }

            if(topMinMiddle && bottomMaxMiddle && totalMiddleHeight){
                var map = {};
                var cmd = COM.gef.Command.createCommand({
                    execute: function execute() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            var bounds = model.getLayoutData();
                            map[model.id] = bounds;
                            model.setLayoutData(new COM.draw2d.Rectangle(bounds.x, topMinMiddle + totalMiddleHeight / (selection.length - 2 + 1) * i - bounds.height / 2, bounds.width, bounds.height));
                        }
                    },
                    undo: function undo() {
                        for(var i in selection){
                            if(i == 0 || i == selection.length -1){
                                continue;
                            }
                            var selectionItem = selection[i];
                            var model = selectionItem.model;
                            model.setLayoutData(map[model.id]);
                        }
                    }
                });

                var commands = new COM.gef.CompoundCommand();
                commands.add(cmd);
                graphicalViewer.getEditDomain().getCommandStack().execute(commands);
            }
        },
        getEnabledState : function(graphicalViewer){
            var selection = graphicalViewer.getSelection();
            if(selection && selection.length > 2){
                var parent = null;
                for(var i in selection){
                    var selectionItem = selection[i];
                    if((parent && selectionItem.parent != parent) || !(selectionItem.model.getLayoutData() instanceof COM.draw2d.Rectangle)){
                        return false;
                    }else{
                        parent = selectionItem.parent;
                    }
                }
                return true;
            }else{
                return false;
            }
        }
    });
})();
/**
 * Created by jiangqifan on 2017/6/20.
 */
(function() {
    ADF.actionModel.CopyModel = function() {
        ADF.actionModel.CopyModel.superclass.constructor.call(this);
        this.config = {text:"复制",icon:"icon-fuzhi"};
        this.id = "copy";
    };

    COM.util.defineClass(ADF.actionModel.CopyModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            var models = [];
            for(var i = 0; i < selections.length; i++){
              models[i] = selections[i].model.serialize();
            }
            this.performCopy(JSON.stringify(models));
        },
        performCopy: function(models){
          ADF.actionModel.CopyModel.clipboard="adfmodels:"+models;
        },
        getEnabledState : function(graphicalViewer){
            var selections = graphicalViewer.getSelection();
            if(!selections){
              return false;
            }
            //Diagram不允许调整顺序
            if(selections.length == 1 && COM.util.isInstanceOf(selections[0], ADF.editpart.DiagramEditPart)){
              return false;
            }
            return selections.length>0;
        }
    });
})();
/**
 * Created by jiangqifan on 2017/6/20.
 */
(function() {
    ADF.actionModel.PasteModel = function() {
        ADF.actionModel.PasteModel.superclass.constructor.call(this);
        this.config = {text:"粘贴",icon:"icon-niantie"};
        this.id = "paste";
    };

    /**
     * 判断editpart是否为容器
     *
     */
    function isComposite(editPart){
      return COM.util.isInstanceOf(editPart, ADF.editpart.DiagramEditPart) ||
             COM.util.isInstanceOf(editPart.model,ADF.model.CompositeModel);
    }

    /**
     * 判断两个模型数组中是否有相同的id
     */
    function hasDuplicateId(models, otherModels){
      var idMap = {};
      var hasDuplicate = false;

      for(var i = 0; i < models.length; i++){
        var model = models[i];
        var id = model.id;
        idMap[id] = true;
      }

      for(var i = 0; i < otherModels.length; i++){
        var model = otherModels[i];
        var id = model.id;
        if(idMap[id]){
          hasDuplicate = true;
          break;
        } else {
          idMap[id] = true;
        }
      }
      return hasDuplicate;
    }

    /**
     * 计算父editpart
     * @param selections 当前选中项
     * @param newModels 需要粘贴的模型
     */
    function calculateParent(selections, newModels){
      var firstSelection = selections[0];
      //如果当前选中Diagram，就复制到Diagram中
      if(COM.util.isInstanceOf(firstSelection, ADF.editpart.DiagramEditPart)){
        return firstSelection;
      }

      //如果是容器，且选中的容器不在剪切版，则复制到此容器中
      if(isComposite(firstSelection)){
        if(!hasDuplicateId(newModels, [firstSelection.model])){
          return firstSelection;
        }
      }

      //如果当前选中中跟要粘贴的内容有相同id，就复制到选中项的父中
      var parent = firstSelection.parent;
      var children = parent.model.getPropertyValue("children");
      if(hasDuplicateId(newModels, children)){
        return parent;
      }

      //如果当前选中是容器，就复制到当前选中项中
      if(isComposite(firstSelection)){
        return firstSelection;
      } else {
        return parent;
      }
    }

    COM.util.defineClass(ADF.actionModel.PasteModel, AGEF.ActionModel, {
        execute: function(graphicalViewer){
            try{
              var clipboardString = this.getCopyModels();
              var selections = graphicalViewer.getSelection();

              if(clipboardString != this.lastPasteContent){
                this.lastPasteContent = clipboardString;
                this.pasteCount = {};
              }

              var outter = this;

              function countPaste(key){
                if(!outter.pasteCount){
                  outter.pasteCount = {};
                  outter.pasteCount[key] = 1;
                }
                if(outter.pasteCount[key]){
                  outter.pasteCount[key]++;
                } else {
                  outter.pasteCount[key] = 1;
                }
              }

              function deCountPaste(key){
                if(!outter.pasteCount){
                }
                if(outter.pasteCount[key]>1){
                  outter.pasteCount[key]--;
                } else {
                  outter.pasteCount[key] = 0;
                }
              }

              function getPasteCount(key){
                if(outter.pasteCount && outter.pasteCount[key]){
                  return outter.pasteCount[key];
                }
                return 0;
              }

              function deserialize(clipboardString, offset){
                var modelStrings = JSON.parse(clipboardString);
                var modelObjecs = [];
                for(var i = 0; i < modelStrings.length; i++){
                  var modelString = modelStrings[i];
                  var model = JSON.parse(modelString);
                  var modelType = model["modelType"], modelConstructor = eval("("+modelType+")");
                  var contentModel = new modelConstructor();
                  contentModel.deserialize(JSON.stringify(model));


                  modelObjecs.push(contentModel);
                }
                return modelObjecs;
              }

              function addOffset(models, offset){
                for(var i = 0; i < models.length; i++ ){
                  var contentModel = models[i];
                  var oldValue = contentModel.getPropertyValue("layoutdata");
                  if(oldValue && oldValue.x !== null && oldValue.x != undefined && oldValue.y != undefined && oldValue.y != undefined ){
                      var newValue = new COM.draw2d.Rectangle();
                      newValue.x = oldValue.x + offset;
                      newValue.y = oldValue.y + offset;
                      newValue.width = oldValue.width;
                      newValue.height = oldValue.height;
                      contentModel.setPropertyValue("layoutdata",newValue);
                  }
                }
              }

              var models = deserialize(clipboardString);
              var parent = calculateParent(selections, models);
              addOffset(models,(getPasteCount(parent.model.id)+1) * 10);

              var cmd = COM.gef.Command.createCommand({
                  models: models,
                  parent: parent,
                  findParentModel: function(){
                    return this.parent.model;
                  },
                  execute: function() {
                    var models = this.models;
                    var parent = this.findParentModel();
                    countPaste(parent.id);
                    var idMap = {};
                    for(var i = 0; i < this.models.length; i++){
                      var id = COM.util.ObjUtil.generateID();
                      idMap[id] = true;
                      models[i].id = id;
                      parent.addChild(models[i]);
                    }

                    //选中新增的model
                    var children = this.parent.children;
                    var toSelectChildren = [];
                    for(var i = 0; i < children.length; i++){
                      if(idMap[children[i].model.id]){
                        toSelectChildren.push(children[i]);
                      }
                    }
                    graphicalViewer.setSelection(toSelectChildren);

                  },

                  undo: function() {
                    var models = this.models;
                    var parent = this.findParentModel();
                    var children = parent.getPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN);
                    var newChildren = children.slice(0, children.length);
                    for(var i=0; i < models.length; i++){
                      newChildren.pop();
                    }

                    deCountPaste(parent.id);
                    parent.setPropertyValue(ADF.model.DiagramModel.PROPERTY_CHILDREN, newChildren);
                  }
              });

              var domain = graphicalViewer.getEditDomain();
              var stack = domain.getCommandStack();
              stack.execute(cmd);

            } catch(e){
              console.debug('粘贴失败');
              return;
            }
        },
        getCopyModels: function(){
          var prefix = "adfmodels:"
          if(ADF.actionModel.CopyModel.clipboard
            && ADF.actionModel.CopyModel.clipboard.substr
            && prefix == ADF.actionModel.CopyModel.clipboard.substr(0,10)){
              return ADF.actionModel.CopyModel.clipboard.substr(10);
          } else {
            return null;
          }

        },
        getEnabledState: function(graphicalViewer){
          if(!this.getCopyModels()){
            return false;
          }
          return true;
        }

    });
})();
(function(){
    ADF.actionModel.CloseTitleModel = function() {
        ADF.actionModel.CloseTitleModel.superclass.constructor.call(this);
        this.config = {text:"关闭标记",icon:"icon-guanbi1"};
        this.id = "closeTitle";
    };

    COM.util.defineClass(ADF.actionModel.CloseTitleModel,AGEF.ActionModel,{
        execute:function(graphicalViewer){
            $(".containerWrap").append('<style>.containerWrap:before{content:"";margin-left:0}</style>');
            $(".rowWrap").append('<style>.rowWrap:before{content:"";margin-left:0}</style>');
            $(".columnWrap").append('<style>.columnWrap:before{content:"";margin-left:0}</style>');
            $(".buttonGroupWrap").append('<style>.buttonGroupWrap:before{content:"";}</style>');
            var rootFigure = graphicalViewer.getRootEditPart().children[0].figure;
            var layout = function(figure){
                if(figure.layoutManager){
                    var children = figure.getChildren(),
                        that = figure;
                    children.forEach(function(child, index, array){
                        if(child.getWidget().needLayout()){
                            child.revalidate();
                        };
                        that.getWidget().layoutChild(child.getWidget());
                        child.getWidget().setLayouted(true);
                        var widgetBounds = child.getWidget().getBounds();
                        var newConstraint = new COM.draw2d.Rectangle(widgetBounds.x, widgetBounds.y, widgetBounds.width, widgetBounds.height);
                        that.getLayoutManager().setConstraint(child, newConstraint);
                        if(child.getChildren && child.getChildren().length){
                            layout(child);
                        }
                    });
                    figure.layoutManager.layout(figure);
                }
            }
            layout(rootFigure);
        }
    })
})();(function(){
    ADF.actionModel.OpenTitleModel = function() {
        ADF.actionModel.OpenTitleModel.superclass.constructor.call(this);
        this.config = {text:"开启标记",icon:"icon-qidong1"};
        this.id = "openTitle";
    };

    COM.util.defineClass(ADF.actionModel.OpenTitleModel,AGEF.ActionModel,{
        execute:function(graphicalViewer){
            $(".containerWrap").append('<style>.containerWrap:before{content:"Container";margin-left:5px;}</style>');
            $(".rowWrap").append('<style>.rowWrap:before{content:"Row";margin-left:5px;}</style>');
            $(".columnWrap").append('<style>.columnWrap:before{content:"Column";margin-left:-10px;}</style>');
            $(".buttonGroupWrap").append('<style>.buttonGroupWrap:before{content:"ButtonGroup";}</style>');
            var rootFigure = graphicalViewer.getRootEditPart().children[0].figure;
            var layout = function(figure){
                if(figure.layoutManager){
                    var children = figure.getChildren(),
                        that = figure;
                    children.forEach(function(child, index, array){
                        if(child.getWidget().needLayout()){
                            child.revalidate();
                        };
                        that.getWidget().layoutChild(child.getWidget());
                        child.getWidget().setLayouted(true);
                        var widgetBounds = child.getWidget().getBounds();
                        var newConstraint = new COM.draw2d.Rectangle(widgetBounds.x, widgetBounds.y, widgetBounds.width, widgetBounds.height);
                        that.getLayoutManager().setConstraint(child, newConstraint);
                        if(child.getChildren && child.getChildren().length){
                            layout(child);
                        }
                    });
                    figure.layoutManager.layout(figure);
                }
            }
            layout(rootFigure);
        }
    })
})();/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.action.DeleteAction = function(type){
    ADF.action.DeleteAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.DeleteAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.DeleteModel();
    }
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.action.RedoAction = function(type){
    ADF.action.RedoAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.RedoAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.RedoModel();
    }
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.action.UndoAction = function(type){
    ADF.action.UndoAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.UndoAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.UndoModel();
    }
});/**
 * @author jiangqifan
 * @since 2017-6-19
 */
ADF.action.TopAction = function(type){
    ADF.action.TopAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.TopAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.TopModel();
    }
});
/**
 * @author jiangqifan
 * @since 2017-6-19
 */
ADF.action.BottomAction = function(type){
    ADF.action.BottomAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.BottomAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.BottomModel();
    }
});
/**
 * @author zhengjiachao
 * @since 2017-6-21
 */
ADF.action.XYUpAction = function(type){
    ADF.action.XYUpAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYUpAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYUpActionModel();
    }
});
/**
 * @author zhengjiachao
 * @since 2017-6-21
 */
ADF.action.XYDownAction = function(type){
    ADF.action.XYDownAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYDownAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYDownActionModel();
    }
});
/**
 * @author zhengjiachao
 * @since 2017-6-21
 */
ADF.action.XYLeftAction = function(type){
    ADF.action.XYLeftAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYLeftAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYLeftActionModel();
    }
});
/**
 * @author zhengjiachao
 * @since 2017-6-21
 */
ADF.action.XYRightAction = function(type){
    ADF.action.XYRightAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYRightAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYRightActionModel();
    }
});
/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignBottomAction = function(type){
    ADF.action.XYAlignBottomAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignBottomAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignBottomModel();
    }
});

/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignCenterAction = function(type){
    ADF.action.XYAlignCenterAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignCenterAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignCenterModel();
    }
});

/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignLeftAction = function(type){
    ADF.action.XYAlignLeftAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignLeftAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignLeftModel();
    }
});

/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignMiddleAction = function(type){
    ADF.action.XYAlignMiddleAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignMiddleAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignMiddleModel();
    }
});

/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignRightAction = function(type){
    ADF.action.XYAlignRightAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignRightAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignRightModel();
    }
});

/**
 * Created by king on 2017/6/21.
 */

ADF.action.XYAlignTopAction = function(type){
    ADF.action.XYAlignTopAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYAlignTopAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYAlignTopModel();
    }
});

/**
 * Created by king on 2017/6/22.
 */

ADF.action.XYDistributeEvenlyAction = function(type){
    ADF.action.XYDistributeEvenlyAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYDistributeEvenlyAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYDistributeEvenlyModel();
    }
});

/**
 * Created by king on 2017/6/22.
 */

ADF.action.XYDistributeHorizontallyAction = function(type){
    ADF.action.XYDistributeHorizontallyAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYDistributeHorizontallyAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYDistributeHorizontallyModel();
    }
});

/**
 * Created by king on 2017/6/22.
 */

ADF.action.XYDistributeVerticallyAction = function(type){
    ADF.action.XYDistributeVerticallyAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.XYDistributeVerticallyAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.XYDistributeVerticallyModel();
    }
});

/**
 * @author jiangqifan
 * @since 2017-6-19
 */
ADF.action.CopyAction = function(type){
    ADF.action.CopyAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.CopyAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.CopyModel();
    }
});
/**
 * @author jiangqifan
 * @since 2017-6-19
 */
ADF.action.PasteAction = function(type){
    ADF.action.PasteAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.PasteAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.PasteModel();
    }
});
ADF.action.CloseTitleAction = function(type){
    ADF.action.CloseTitleAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.CloseTitleAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.CloseTitleModel();
    }
});ADF.action.OpenTitleAction = function(type){
    ADF.action.OpenTitleAction.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.action.OpenTitleAction, ADF.ActionDescriptor,{

    getModelInstance : function(){
        return new ADF.actionModel.OpenTitleModel();
    }
});